Skip to content

Commit 34d8fa2

Browse files
committed
Apply suggestions
1 parent 250b2c7 commit 34d8fa2

File tree

3 files changed

+71
-44
lines changed

3 files changed

+71
-44
lines changed

src/sage/misc/superseded.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,18 @@ class DeprecatedFunctionAlias:
350350
- Florent Hivert (2009-11-23), with the help of Mike Hansen.
351351
- Luca De Feo (2011-07-11), printing the full module path when different from old path
352352
"""
353-
def __init__(self, issue_number, func, module, instance=None, unbound=None):
353+
def __init__(self, issue_number, func, module, instance=None, unbound=None, *, replacement=None, replacement_rst_doc=None):
354354
r"""
355355
TESTS::
356356
357+
sage: # needs sage.combinat
357358
sage: from sage.misc.superseded import deprecated_function_alias
358-
sage: g = deprecated_function_alias(13109, number_of_partitions) # needs sage.combinat
359-
sage: from sage.misc.superseded import deprecated_function_alias
360-
sage: g.__doc__ # needs sage.combinat
359+
sage: g = deprecated_function_alias(13109, number_of_partitions)
360+
sage: g.__doc__
361361
'Deprecated: Use :func:`number_of_partitions` instead.\nSee :issue:`13109` for details.\n\n'
362+
sage: g = deprecated_function_alias(13109, number_of_partitions, replacement_rst_doc='BLOB')
363+
sage: g.__doc__
364+
'Deprecated: Use BLOB instead.\nSee :issue:`13109` for details.\n\n'
362365
"""
363366
_check_issue_number(issue_number)
364367
try:
@@ -369,14 +372,15 @@ def __init__(self, issue_number, func, module, instance=None, unbound=None):
369372
self.issue_number = issue_number
370373
self.instance = instance # for use with methods
371374
self.unbound = unbound
375+
self._replacement = replacement
372376
self.__module__ = module
373-
if isinstance(func, type(deprecation)):
374-
sphinxrole = "func"
375-
else:
376-
sphinxrole = "meth"
377-
doc = 'Deprecated: '
378-
doc += 'Use :' + sphinxrole + ':`' + self.func.__name__ + '` instead.\n'
379-
doc += 'See :issue:`' + str(self.issue_number) + '` for details.\n\n'
377+
if replacement_rst_doc is None:
378+
if isinstance(func, type(deprecation)):
379+
replacement_rst_doc = f":func:`{self.func.__name__}`"
380+
else:
381+
replacement_rst_doc = f":meth:`{self.func.__name__}`"
382+
doc = f'Deprecated: Use {replacement_rst_doc} instead.\n'
383+
doc += f'See :issue:`{self.issue_number}` for details.\n\n'
380384
self.__doc__ = doc
381385

382386
@lazy_attribute
@@ -389,7 +393,6 @@ def __name__(self):
389393
sage: g.__name__ # needs sage.combinat
390394
'g'
391395
392-
sage: from sage.misc.superseded import deprecated_function_alias
393396
sage: class cls():
394397
....: def new_meth(self): return 42
395398
....: old_meth = deprecated_function_alias(13109, new_meth)
@@ -444,15 +447,21 @@ def __call__(self, *args, **kwds):
444447
doctest:...: DeprecationWarning: blo is deprecated. Please use bla instead.
445448
See https://github.com/sagemath/sage/issues/13109 for details.
446449
42
450+
sage: blo = deprecated_function_alias(13109, bla, replacement='BLOB')
451+
sage: blo()
452+
doctest:...: DeprecationWarning: blo is deprecated. Please use BLOB instead.
453+
See https://github.com/sagemath/sage/issues/13109 for details.
454+
42
447455
"""
448-
if self.instance is None and self.__module__ != self.func.__module__:
449-
other = self.func.__module__ + "." + self.func.__name__
450-
else:
451-
other = self.func.__name__
456+
replacement = self._replacement
457+
if replacement is None:
458+
if self.instance is None and self.__module__ != self.func.__module__:
459+
replacement = self.func.__module__ + "." + self.func.__name__
460+
else:
461+
replacement = self.func.__name__
452462

453463
deprecation(self.issue_number,
454-
"{} is deprecated. Please use {} instead.".format(
455-
self.__name__, other))
464+
f"{self.__name__} is deprecated. Please use {replacement} instead.")
456465
if self.instance is None:
457466
return self.func(*args, **kwds)
458467
else:
@@ -497,7 +506,7 @@ def __get__(self, inst, cls=None):
497506
unbound=self)
498507

499508

500-
def deprecated_function_alias(issue_number, func):
509+
def deprecated_function_alias(issue_number, func, *, replacement=None, replacement_rst_doc=None):
501510
"""
502511
Create an aliased version of a function or a method which raises a
503512
deprecation warning message.
@@ -513,6 +522,12 @@ def deprecated_function_alias(issue_number, func):
513522
514523
- ``func`` -- the function or method to be aliased
515524
525+
- ``replacement`` -- a plain text string to be inserted
526+
into the warning message to describe the replacement
527+
528+
- ``replacement_rst_doc`` -- a restructuredText snippet to be inserted
529+
into the user documentation to describe the replacement
530+
516531
EXAMPLES::
517532
518533
sage: from sage.misc.superseded import deprecated_function_alias
@@ -554,4 +569,5 @@ def deprecated_function_alias(issue_number, func):
554569
module_name = inspect.getmodulename(frame1.f_code.co_filename)
555570
if module_name is None:
556571
module_name = '__main__'
557-
return DeprecatedFunctionAlias(issue_number, func, module_name)
572+
return DeprecatedFunctionAlias(issue_number, func, module_name,
573+
replacement=replacement, replacement_rst_doc=replacement_rst_doc)

src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,7 @@ def frobenius_matrix(self, N=None, algorithm='hypellfrob'):
309309

310310
def _frobenius_polynomial_cardinalities(self, a=None):
311311
r"""
312-
Compute the charpoly of frobenius, as an element of `\ZZ[x]`,
313-
by computing the number of points on the curve over `g` extensions
314-
of the base field where `g` is the genus of the curve.
315-
316-
.. WARNING::
317-
318-
This is highly inefficient when the base field or the genus of the
319-
curve are large.
312+
Helper method for :meth:`frobenius_polynomial`.
320313
321314
EXAMPLES::
322315
@@ -375,11 +368,7 @@ def _frobenius_polynomial_cardinalities(self, a=None):
375368

376369
def _frobenius_polynomial_matrix(self, M=None, algorithm='hypellfrob'):
377370
r"""
378-
Compute the charpoly of frobenius, as an element of `\ZZ[x]`,
379-
by computing the charpoly of the frobenius matrix.
380-
381-
This is currently only supported when the base field is prime
382-
and large enough using the ``hypellfrob`` library.
371+
Helper method for :meth:`frobenius_polynomial`.
383372
384373
EXAMPLES::
385374
@@ -443,8 +432,7 @@ def _frobenius_polynomial_matrix(self, M=None, algorithm='hypellfrob'):
443432

444433
def _frobenius_polynomial_pari(self):
445434
r"""
446-
Compute the charpoly of frobenius, as an element of `\ZZ[x]`,
447-
by calling the PARI function ``hyperellcharpoly``.
435+
Helper method for :meth:`frobenius_polynomial`.
448436
449437
EXAMPLES::
450438
@@ -502,9 +490,18 @@ def _frobenius_polynomial_pari(self):
502490
f, h = self.hyperelliptic_polynomials()
503491
return ZZ['x'](pari([f, h]).hyperellcharpoly())
504492

505-
frobenius_polynomial_cardinalities = deprecated_function_alias(40528, _frobenius_polynomial_cardinalities)
506-
frobenius_polynomial_matrix = deprecated_function_alias(40528, _frobenius_polynomial_matrix)
507-
frobenius_polynomial_pari = deprecated_function_alias(40528, _frobenius_polynomial_pari)
493+
frobenius_polynomial_cardinalities = deprecated_function_alias(
494+
40528, _frobenius_polynomial_cardinalities,
495+
replacement='frobenius_polynomial(algorithm="cardinalities")',
496+
replacement_rst_doc=':meth:`frobenius_polynomial` ``(algorithm="cardinalities")``')
497+
frobenius_polynomial_matrix = deprecated_function_alias(
498+
40528, _frobenius_polynomial_matrix,
499+
replacement='frobenius_polynomial(algorithm="matrix")',
500+
replacement_rst_doc=':meth:`frobenius_polynomial` ``(algorithm="matrix")`')
501+
frobenius_polynomial_pari = deprecated_function_alias(
502+
40528, _frobenius_polynomial_pari,
503+
replacement='frobenius_polynomial(algorithm="pari")',
504+
replacement_rst_doc=':meth:`frobenius_polynomial` ``(algorithm="pari")`')
508505

509506
@cached_method
510507
def frobenius_polynomial(self, algorithm=None, **kwargs):
@@ -513,15 +510,27 @@ def frobenius_polynomial(self, algorithm=None, **kwargs):
513510
514511
INPUT:
515512
516-
- ``algorithm`` -- (default: ``None``) the algorithm to use, one of
517-
``'cardinalities'``, ``'matrix'``, or ``'pari'``.
513+
- ``algorithm`` -- the algorithm to use, one of
514+
515+
- ``None`` (default) -- automatically select an algorithm.
516+
517+
- ``'pari'`` -- use the PARI function ``hyperellcharpoly``.
518+
519+
- ``'cardinalities'`` -- compute the number of points on the curve over `g`
520+
extensions of the base field where `g` is the genus of the curve.
521+
522+
.. WARNING::
523+
524+
This is highly inefficient when the base field or the genus of the
525+
curve are large.
526+
527+
- ``'matrix'`` -- compute the charpoly of the frobenius matrix.
518528
519-
Refer to :meth:`frobenius_polynomial_cardinalities`,
520-
:meth:`frobenius_polynomial_matrix`, and
521-
:meth:`frobenius_polynomial_pari` respectively.
529+
This is currently only supported when the base field is prime
530+
and large enough using the ``hypellfrob`` library.
522531
523532
- ``**kwargs`` -- additional keyword arguments passed to the
524-
methods above. Undocumented feature, may be removed in the future.
533+
internal method. Undocumented feature, may be removed in the future.
525534
526535
EXAMPLES::
527536

src/sage/schemes/hyperelliptic_curves/jacobian_generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ def cardinality(self):
422422
Return the cardinality of the Jacobian.
423423
Use the formula in `<https://math.stackexchange.com/a/2190894>`_.
424424
425+
Currently only implemented over finite fields.
426+
425427
EXAMPLES::
426428
427429
sage: R.<x> = GF(3663031)[]

0 commit comments

Comments
 (0)