passagemath-objects 10.6.41__cp314-cp314t-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-objects might be problematic. Click here for more details.
- passagemath_objects/.dylibs/libgmp.10.dylib +0 -0
- passagemath_objects/__init__.py +3 -0
- passagemath_objects-10.6.41.dist-info/METADATA +115 -0
- passagemath_objects-10.6.41.dist-info/RECORD +280 -0
- passagemath_objects-10.6.41.dist-info/WHEEL +6 -0
- passagemath_objects-10.6.41.dist-info/top_level.txt +3 -0
- sage/all__sagemath_objects.py +37 -0
- sage/arith/all__sagemath_objects.py +5 -0
- sage/arith/long.pxd +411 -0
- sage/arith/numerical_approx.cpython-314t-darwin.so +0 -0
- sage/arith/numerical_approx.pxd +35 -0
- sage/arith/numerical_approx.pyx +75 -0
- sage/arith/power.cpython-314t-darwin.so +0 -0
- sage/arith/power.pxd +31 -0
- sage/arith/power.pyx +127 -0
- sage/categories/action.cpython-314t-darwin.so +0 -0
- sage/categories/action.pxd +29 -0
- sage/categories/action.pyx +641 -0
- sage/categories/algebra_functor.py +745 -0
- sage/categories/all__sagemath_objects.py +33 -0
- sage/categories/basic.py +62 -0
- sage/categories/cartesian_product.py +295 -0
- sage/categories/category.py +3401 -0
- sage/categories/category_cy_helper.cpython-314t-darwin.so +0 -0
- sage/categories/category_cy_helper.pxd +8 -0
- sage/categories/category_cy_helper.pyx +322 -0
- sage/categories/category_singleton.cpython-314t-darwin.so +0 -0
- sage/categories/category_singleton.pxd +3 -0
- sage/categories/category_singleton.pyx +342 -0
- sage/categories/category_types.py +637 -0
- sage/categories/category_with_axiom.py +2876 -0
- sage/categories/covariant_functorial_construction.py +703 -0
- sage/categories/facade_sets.py +228 -0
- sage/categories/functor.cpython-314t-darwin.so +0 -0
- sage/categories/functor.pxd +7 -0
- sage/categories/functor.pyx +691 -0
- sage/categories/homset.py +1338 -0
- sage/categories/homsets.py +364 -0
- sage/categories/isomorphic_objects.py +73 -0
- sage/categories/map.cpython-314t-darwin.so +0 -0
- sage/categories/map.pxd +34 -0
- sage/categories/map.pyx +2112 -0
- sage/categories/morphism.cpython-314t-darwin.so +0 -0
- sage/categories/morphism.pxd +14 -0
- sage/categories/morphism.pyx +895 -0
- sage/categories/objects.py +167 -0
- sage/categories/primer.py +1696 -0
- sage/categories/pushout.py +4834 -0
- sage/categories/quotients.py +64 -0
- sage/categories/realizations.py +200 -0
- sage/categories/sets_cat.py +3228 -0
- sage/categories/sets_with_partial_maps.py +52 -0
- sage/categories/subobjects.py +64 -0
- sage/categories/subquotients.py +21 -0
- sage/categories/with_realizations.py +311 -0
- sage/cpython/__init__.py +19 -0
- sage/cpython/_py2_random.py +619 -0
- sage/cpython/all.py +3 -0
- sage/cpython/atexit.cpython-314t-darwin.so +0 -0
- sage/cpython/atexit.pyx +269 -0
- sage/cpython/builtin_types.cpython-314t-darwin.so +0 -0
- sage/cpython/builtin_types.pyx +7 -0
- sage/cpython/cython_metaclass.cpython-314t-darwin.so +0 -0
- sage/cpython/cython_metaclass.h +117 -0
- sage/cpython/cython_metaclass.pxd +3 -0
- sage/cpython/cython_metaclass.pyx +130 -0
- sage/cpython/debug.cpython-314t-darwin.so +0 -0
- sage/cpython/debug.pyx +302 -0
- sage/cpython/dict_del_by_value.cpython-314t-darwin.so +0 -0
- sage/cpython/dict_del_by_value.pxd +9 -0
- sage/cpython/dict_del_by_value.pyx +191 -0
- sage/cpython/dict_internal.h +245 -0
- sage/cpython/getattr.cpython-314t-darwin.so +0 -0
- sage/cpython/getattr.pxd +9 -0
- sage/cpython/getattr.pyx +439 -0
- sage/cpython/pycore_long.h +97 -0
- sage/cpython/pycore_long.pxd +10 -0
- sage/cpython/python_debug.h +44 -0
- sage/cpython/python_debug.pxd +47 -0
- sage/cpython/pyx_visit.h +13 -0
- sage/cpython/string.cpython-314t-darwin.so +0 -0
- sage/cpython/string.pxd +76 -0
- sage/cpython/string.pyx +34 -0
- sage/cpython/string_impl.h +60 -0
- sage/cpython/type.cpython-314t-darwin.so +0 -0
- sage/cpython/type.pxd +2 -0
- sage/cpython/type.pyx +40 -0
- sage/cpython/wrapperdescr.pxd +67 -0
- sage/ext/all__sagemath_objects.py +3 -0
- sage/ext/ccobject.h +64 -0
- sage/ext/cplusplus.pxd +17 -0
- sage/ext/mod_int.h +30 -0
- sage/ext/mod_int.pxd +24 -0
- sage/ext/stdsage.pxd +39 -0
- sage/groups/all__sagemath_objects.py +1 -0
- sage/groups/group.cpython-314t-darwin.so +0 -0
- sage/groups/group.pxd +14 -0
- sage/groups/group.pyx +322 -0
- sage/groups/old.cpython-314t-darwin.so +0 -0
- sage/groups/old.pxd +14 -0
- sage/groups/old.pyx +219 -0
- sage/libs/all__sagemath_objects.py +3 -0
- sage/libs/gmp/__init__.py +1 -0
- sage/libs/gmp/all.pxd +6 -0
- sage/libs/gmp/binop.pxd +23 -0
- sage/libs/gmp/misc.pxd +8 -0
- sage/libs/gmp/mpf.pxd +88 -0
- sage/libs/gmp/mpn.pxd +57 -0
- sage/libs/gmp/mpq.pxd +57 -0
- sage/libs/gmp/mpz.pxd +202 -0
- sage/libs/gmp/pylong.cpython-314t-darwin.so +0 -0
- sage/libs/gmp/pylong.pxd +12 -0
- sage/libs/gmp/pylong.pyx +150 -0
- sage/libs/gmp/random.pxd +25 -0
- sage/libs/gmp/randomize.pxd +59 -0
- sage/libs/gmp/types.pxd +53 -0
- sage/libs/gmpxx.pxd +19 -0
- sage/misc/abstract_method.py +276 -0
- sage/misc/all__sagemath_objects.py +43 -0
- sage/misc/bindable_class.py +253 -0
- sage/misc/c3_controlled.cpython-314t-darwin.so +0 -0
- sage/misc/c3_controlled.pxd +2 -0
- sage/misc/c3_controlled.pyx +1402 -0
- sage/misc/cachefunc.cpython-314t-darwin.so +0 -0
- sage/misc/cachefunc.pxd +43 -0
- sage/misc/cachefunc.pyx +3781 -0
- sage/misc/call.py +188 -0
- sage/misc/classcall_metaclass.cpython-314t-darwin.so +0 -0
- sage/misc/classcall_metaclass.pxd +14 -0
- sage/misc/classcall_metaclass.pyx +599 -0
- sage/misc/constant_function.cpython-314t-darwin.so +0 -0
- sage/misc/constant_function.pyx +130 -0
- sage/misc/decorators.py +747 -0
- sage/misc/fast_methods.cpython-314t-darwin.so +0 -0
- sage/misc/fast_methods.pxd +20 -0
- sage/misc/fast_methods.pyx +351 -0
- sage/misc/flatten.py +90 -0
- sage/misc/fpickle.cpython-314t-darwin.so +0 -0
- sage/misc/fpickle.pyx +177 -0
- sage/misc/function_mangling.cpython-314t-darwin.so +0 -0
- sage/misc/function_mangling.pxd +11 -0
- sage/misc/function_mangling.pyx +308 -0
- sage/misc/inherit_comparison.cpython-314t-darwin.so +0 -0
- sage/misc/inherit_comparison.pxd +5 -0
- sage/misc/inherit_comparison.pyx +105 -0
- sage/misc/instancedoc.cpython-314t-darwin.so +0 -0
- sage/misc/instancedoc.pyx +331 -0
- sage/misc/lazy_attribute.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_attribute.pyx +607 -0
- sage/misc/lazy_format.py +135 -0
- sage/misc/lazy_import.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_import.pyx +1299 -0
- sage/misc/lazy_import_cache.py +36 -0
- sage/misc/lazy_list.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_list.pxd +19 -0
- sage/misc/lazy_list.pyx +1187 -0
- sage/misc/lazy_string.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_string.pxd +7 -0
- sage/misc/lazy_string.pyx +546 -0
- sage/misc/misc.py +1066 -0
- sage/misc/misc_c.cpython-314t-darwin.so +0 -0
- sage/misc/misc_c.pxd +3 -0
- sage/misc/misc_c.pyx +766 -0
- sage/misc/namespace_package.py +37 -0
- sage/misc/nested_class.cpython-314t-darwin.so +0 -0
- sage/misc/nested_class.pxd +3 -0
- sage/misc/nested_class.pyx +394 -0
- sage/misc/persist.cpython-314t-darwin.so +0 -0
- sage/misc/persist.pyx +1251 -0
- sage/misc/prandom.py +418 -0
- sage/misc/randstate.cpython-314t-darwin.so +0 -0
- sage/misc/randstate.pxd +30 -0
- sage/misc/randstate.pyx +1059 -0
- sage/misc/repr.py +203 -0
- sage/misc/reset.cpython-314t-darwin.so +0 -0
- sage/misc/reset.pyx +196 -0
- sage/misc/sage_ostools.cpython-314t-darwin.so +0 -0
- sage/misc/sage_ostools.pyx +323 -0
- sage/misc/sage_timeit.py +276 -0
- sage/misc/sage_timeit_class.cpython-314t-darwin.so +0 -0
- sage/misc/sage_timeit_class.pyx +120 -0
- sage/misc/sage_unittest.py +637 -0
- sage/misc/sageinspect.py +2768 -0
- sage/misc/session.cpython-314t-darwin.so +0 -0
- sage/misc/session.pyx +392 -0
- sage/misc/superseded.py +557 -0
- sage/misc/test_nested_class.py +228 -0
- sage/misc/timing.py +264 -0
- sage/misc/unknown.py +222 -0
- sage/misc/verbose.py +253 -0
- sage/misc/weak_dict.cpython-314t-darwin.so +0 -0
- sage/misc/weak_dict.pxd +15 -0
- sage/misc/weak_dict.pyx +1231 -0
- sage/modules/all__sagemath_objects.py +1 -0
- sage/modules/module.cpython-314t-darwin.so +0 -0
- sage/modules/module.pxd +5 -0
- sage/modules/module.pyx +329 -0
- sage/rings/all__sagemath_objects.py +3 -0
- sage/rings/integer_fake.h +22 -0
- sage/rings/integer_fake.pxd +55 -0
- sage/sets/all__sagemath_objects.py +3 -0
- sage/sets/pythonclass.cpython-314t-darwin.so +0 -0
- sage/sets/pythonclass.pxd +9 -0
- sage/sets/pythonclass.pyx +247 -0
- sage/structure/__init__.py +4 -0
- sage/structure/all.py +30 -0
- sage/structure/category_object.cpython-314t-darwin.so +0 -0
- sage/structure/category_object.pxd +28 -0
- sage/structure/category_object.pyx +1087 -0
- sage/structure/coerce.cpython-314t-darwin.so +0 -0
- sage/structure/coerce.pxd +44 -0
- sage/structure/coerce.pyx +2107 -0
- sage/structure/coerce_actions.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_actions.pxd +27 -0
- sage/structure/coerce_actions.pyx +988 -0
- sage/structure/coerce_dict.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_dict.pxd +51 -0
- sage/structure/coerce_dict.pyx +1557 -0
- sage/structure/coerce_exceptions.py +23 -0
- sage/structure/coerce_maps.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_maps.pxd +28 -0
- sage/structure/coerce_maps.pyx +718 -0
- sage/structure/debug_options.cpython-314t-darwin.so +0 -0
- sage/structure/debug_options.pxd +6 -0
- sage/structure/debug_options.pyx +54 -0
- sage/structure/dynamic_class.py +541 -0
- sage/structure/element.cpython-314t-darwin.so +0 -0
- sage/structure/element.pxd +272 -0
- sage/structure/element.pyx +4772 -0
- sage/structure/element_wrapper.cpython-314t-darwin.so +0 -0
- sage/structure/element_wrapper.pxd +12 -0
- sage/structure/element_wrapper.pyx +582 -0
- sage/structure/factorization.py +1422 -0
- sage/structure/factorization_integer.py +105 -0
- sage/structure/factory.cpython-314t-darwin.so +0 -0
- sage/structure/factory.pyx +786 -0
- sage/structure/formal_sum.py +489 -0
- sage/structure/gens_py.py +73 -0
- sage/structure/global_options.py +1743 -0
- sage/structure/indexed_generators.py +863 -0
- sage/structure/list_clone.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone.pxd +65 -0
- sage/structure/list_clone.pyx +1867 -0
- sage/structure/list_clone_demo.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone_demo.pyx +248 -0
- sage/structure/list_clone_timings.py +179 -0
- sage/structure/list_clone_timings_cy.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone_timings_cy.pyx +86 -0
- sage/structure/mutability.cpython-314t-darwin.so +0 -0
- sage/structure/mutability.pxd +21 -0
- sage/structure/mutability.pyx +348 -0
- sage/structure/nonexact.py +69 -0
- sage/structure/parent.cpython-314t-darwin.so +0 -0
- sage/structure/parent.pxd +112 -0
- sage/structure/parent.pyx +3093 -0
- sage/structure/parent_base.cpython-314t-darwin.so +0 -0
- sage/structure/parent_base.pxd +13 -0
- sage/structure/parent_base.pyx +44 -0
- sage/structure/parent_gens.cpython-314t-darwin.so +0 -0
- sage/structure/parent_gens.pxd +22 -0
- sage/structure/parent_gens.pyx +377 -0
- sage/structure/parent_old.cpython-314t-darwin.so +0 -0
- sage/structure/parent_old.pxd +25 -0
- sage/structure/parent_old.pyx +294 -0
- sage/structure/proof/__init__.py +1 -0
- sage/structure/proof/all.py +243 -0
- sage/structure/proof/proof.py +300 -0
- sage/structure/richcmp.cpython-314t-darwin.so +0 -0
- sage/structure/richcmp.pxd +213 -0
- sage/structure/richcmp.pyx +495 -0
- sage/structure/sage_object.cpython-314t-darwin.so +0 -0
- sage/structure/sage_object.pxd +3 -0
- sage/structure/sage_object.pyx +988 -0
- sage/structure/sage_object_test.py +19 -0
- sage/structure/sequence.py +937 -0
- sage/structure/set_factories.py +1178 -0
- sage/structure/set_factories_example.py +527 -0
- sage/structure/support_view.py +179 -0
- sage/structure/test_factory.py +56 -0
- sage/structure/unique_representation.py +1359 -0
sage/misc/superseded.py
ADDED
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
Handling Superseded Functionality
|
|
4
|
+
|
|
5
|
+
The main mechanism in Sage to deal with superseded functionality is to
|
|
6
|
+
add a deprecation warning. This will be shown once, the first time
|
|
7
|
+
that the deprecated function is called.
|
|
8
|
+
|
|
9
|
+
Note that all doctests in the following use the github issue number
|
|
10
|
+
:issue:`13109`, which is where this mandatory argument to
|
|
11
|
+
:func:`deprecation` was introduced.
|
|
12
|
+
|
|
13
|
+
Functions and classes
|
|
14
|
+
---------------------
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
########################################################################
|
|
19
|
+
# Copyright (C) 2012 William Stein <wstein@gmail.com>
|
|
20
|
+
#
|
|
21
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
22
|
+
#
|
|
23
|
+
# https://www.gnu.org/licenses/
|
|
24
|
+
########################################################################
|
|
25
|
+
|
|
26
|
+
from warnings import warn
|
|
27
|
+
import inspect
|
|
28
|
+
|
|
29
|
+
from sage.misc.lazy_attribute import lazy_attribute
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _check_issue_number(issue_number):
|
|
33
|
+
"""
|
|
34
|
+
Check that the argument is likely to be a valid github issue number.
|
|
35
|
+
|
|
36
|
+
INPUT:
|
|
37
|
+
|
|
38
|
+
- ``issue_number`` -- anything
|
|
39
|
+
|
|
40
|
+
OUTPUT:
|
|
41
|
+
|
|
42
|
+
This function returns nothing. A :exc:`ValueError` or :exc:`TypeError`
|
|
43
|
+
is raised if the argument cannot be a valid issue number.
|
|
44
|
+
|
|
45
|
+
EXAMPLES::
|
|
46
|
+
|
|
47
|
+
sage: from sage.misc.superseded import _check_issue_number
|
|
48
|
+
sage: _check_issue_number(1)
|
|
49
|
+
sage: _check_issue_number(0)
|
|
50
|
+
Traceback (most recent call last):
|
|
51
|
+
...
|
|
52
|
+
ValueError: 0 is not a valid github issue number
|
|
53
|
+
sage: _check_issue_number(int(10))
|
|
54
|
+
sage: _check_issue_number(10.0)
|
|
55
|
+
Traceback (most recent call last):
|
|
56
|
+
...
|
|
57
|
+
TypeError: 10.0... is not a valid github issue number
|
|
58
|
+
sage: _check_issue_number('10')
|
|
59
|
+
Traceback (most recent call last):
|
|
60
|
+
...
|
|
61
|
+
TypeError: '10' is not a valid github issue number
|
|
62
|
+
"""
|
|
63
|
+
try:
|
|
64
|
+
issue_number = issue_number.__index__()
|
|
65
|
+
except Exception:
|
|
66
|
+
raise TypeError('%r is not a valid github issue number' % issue_number)
|
|
67
|
+
if issue_number <= 0:
|
|
68
|
+
raise ValueError('%r is not a valid github issue number' % issue_number)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def deprecation(issue_number, message, stacklevel=4):
|
|
72
|
+
r"""
|
|
73
|
+
Issue a deprecation warning.
|
|
74
|
+
|
|
75
|
+
INPUT:
|
|
76
|
+
|
|
77
|
+
- ``issue_number`` -- integer; the github issue number where the
|
|
78
|
+
deprecation is introduced
|
|
79
|
+
|
|
80
|
+
- ``message`` -- string; an explanation why things are deprecated
|
|
81
|
+
and by what it should be replaced
|
|
82
|
+
|
|
83
|
+
- ``stack_level`` -- integer (default: `4`); this is passed on to
|
|
84
|
+
:func:`warnings.warn`
|
|
85
|
+
|
|
86
|
+
EXAMPLES::
|
|
87
|
+
|
|
88
|
+
sage: def foo():
|
|
89
|
+
....: sage.misc.superseded.deprecation(13109, 'the function foo is replaced by bar')
|
|
90
|
+
sage: foo()
|
|
91
|
+
doctest:...: DeprecationWarning: the function foo is replaced by bar
|
|
92
|
+
See https://github.com/sagemath/sage/issues/13109 for details.
|
|
93
|
+
|
|
94
|
+
.. SEEALSO::
|
|
95
|
+
|
|
96
|
+
:func:`experimental`,
|
|
97
|
+
:func:`warning`.
|
|
98
|
+
"""
|
|
99
|
+
warning(issue_number, message, DeprecationWarning, stacklevel)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def deprecation_cython(issue_number, message, stacklevel=3):
|
|
103
|
+
r"""
|
|
104
|
+
Issue a deprecation warning -- for use in cython functions.
|
|
105
|
+
|
|
106
|
+
TESTS:
|
|
107
|
+
|
|
108
|
+
We check that ``deprecation_cython`` in a cython function generates a warning
|
|
109
|
+
with the same callsite reference as `deprecation` in a python function, whereas
|
|
110
|
+
`deprecation` in a cython function does not::
|
|
111
|
+
|
|
112
|
+
sage: # needs sage.misc.cython
|
|
113
|
+
sage: cython(
|
|
114
|
+
....: '''
|
|
115
|
+
....: from sage.misc.superseded import deprecation_cython, deprecation
|
|
116
|
+
....: def foo1():
|
|
117
|
+
....: deprecation_cython(100, "boo")
|
|
118
|
+
....: def foo2():
|
|
119
|
+
....: deprecation(100, "boo")
|
|
120
|
+
....: ''')
|
|
121
|
+
sage: def foo3():
|
|
122
|
+
....: deprecation(100, "boo")
|
|
123
|
+
sage: if True: # Execute the three "with" blocks as one doctest
|
|
124
|
+
....: with warnings.catch_warnings(record=True) as w1:
|
|
125
|
+
....: warnings.simplefilter("always")
|
|
126
|
+
....: foo1()
|
|
127
|
+
....: with warnings.catch_warnings(record=True) as w2:
|
|
128
|
+
....: warnings.simplefilter("always")
|
|
129
|
+
....: foo2()
|
|
130
|
+
....: with warnings.catch_warnings(record=True) as w3:
|
|
131
|
+
....: warnings.simplefilter("always")
|
|
132
|
+
....: foo3()
|
|
133
|
+
sage: w1[0].filename == w3[0].filename
|
|
134
|
+
True
|
|
135
|
+
sage: w2[0].filename == w3[0].filename
|
|
136
|
+
False
|
|
137
|
+
"""
|
|
138
|
+
warning(issue_number, message, DeprecationWarning, stacklevel)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def warning(issue_number, message, warning_class=Warning, stacklevel=3):
|
|
142
|
+
r"""
|
|
143
|
+
Issue a warning.
|
|
144
|
+
|
|
145
|
+
INPUT:
|
|
146
|
+
|
|
147
|
+
- ``issue_number`` -- integer; the github issue number where the
|
|
148
|
+
deprecation is introduced
|
|
149
|
+
|
|
150
|
+
- ``message`` -- string; an explanation what is going on
|
|
151
|
+
|
|
152
|
+
- ``warning_class`` -- (default: ``Warning``) a class inherited
|
|
153
|
+
from a Python :class:`~exceptions.Warning`
|
|
154
|
+
|
|
155
|
+
- ``stack_level`` -- integer (default: `3`); this is passed on to
|
|
156
|
+
:func:`warnings.warn`
|
|
157
|
+
|
|
158
|
+
EXAMPLES::
|
|
159
|
+
|
|
160
|
+
sage: def foo():
|
|
161
|
+
....: sage.misc.superseded.warning(
|
|
162
|
+
....: 99999,
|
|
163
|
+
....: 'The syntax will change in future.',
|
|
164
|
+
....: FutureWarning)
|
|
165
|
+
sage: foo()
|
|
166
|
+
doctest:...: FutureWarning: The syntax will change in future.
|
|
167
|
+
See https://github.com/sagemath/sage/issues/99999 for details.
|
|
168
|
+
|
|
169
|
+
.. SEEALSO::
|
|
170
|
+
|
|
171
|
+
:func:`deprecation`,
|
|
172
|
+
:func:`experimental`,
|
|
173
|
+
:class:`exceptions.Warning`.
|
|
174
|
+
"""
|
|
175
|
+
_check_issue_number(issue_number)
|
|
176
|
+
message += '\nSee https://github.com/sagemath/sage/issues/' + str(issue_number) + ' for details.'
|
|
177
|
+
|
|
178
|
+
# Stack level 3 to get the line number of the code which called
|
|
179
|
+
# the deprecated function which called this function.
|
|
180
|
+
warn(message, warning_class, stacklevel)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def experimental_warning(issue_number, message, stacklevel=4):
|
|
184
|
+
r"""
|
|
185
|
+
Issue a warning that the functionality or class is experimental
|
|
186
|
+
and might change in future.
|
|
187
|
+
|
|
188
|
+
INPUT:
|
|
189
|
+
|
|
190
|
+
- ``issue_number`` -- integer; the github issue number where the
|
|
191
|
+
experimental functionality was introduced
|
|
192
|
+
|
|
193
|
+
- ``message`` -- string; an explanation what is going on
|
|
194
|
+
|
|
195
|
+
- ``stack_level`` -- integer (default: `4`); this is passed on to
|
|
196
|
+
:func:`warnings.warn`
|
|
197
|
+
|
|
198
|
+
EXAMPLES::
|
|
199
|
+
|
|
200
|
+
sage: def foo():
|
|
201
|
+
....: sage.misc.superseded.experimental_warning(
|
|
202
|
+
....: 66666, 'This function is experimental and '
|
|
203
|
+
....: 'might change in future.')
|
|
204
|
+
sage: foo()
|
|
205
|
+
doctest:...: FutureWarning: This function is experimental and
|
|
206
|
+
might change in future.
|
|
207
|
+
See https://github.com/sagemath/sage/issues/66666 for details.
|
|
208
|
+
|
|
209
|
+
.. SEEALSO::
|
|
210
|
+
|
|
211
|
+
:class:`mark_as_experimental`,
|
|
212
|
+
:func:`warning`,
|
|
213
|
+
:func:`deprecation`.
|
|
214
|
+
"""
|
|
215
|
+
warning(issue_number, message, FutureWarning, stacklevel)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class experimental:
|
|
219
|
+
def __init__(self, issue_number, stacklevel=4):
|
|
220
|
+
"""
|
|
221
|
+
A decorator which warns about the experimental/unstable status of
|
|
222
|
+
the decorated class/method/function.
|
|
223
|
+
|
|
224
|
+
INPUT:
|
|
225
|
+
|
|
226
|
+
- ``issue_number`` -- integer; the github issue number where this
|
|
227
|
+
code was introduced
|
|
228
|
+
|
|
229
|
+
- ``stack_level`` -- integer (default: `4`); this is passed on to
|
|
230
|
+
:func:`warnings.warn`
|
|
231
|
+
|
|
232
|
+
EXAMPLES::
|
|
233
|
+
|
|
234
|
+
sage: @sage.misc.superseded.experimental(issue_number=79997)
|
|
235
|
+
....: def foo(*args, **kwargs):
|
|
236
|
+
....: print("{} {}".format(args, kwargs))
|
|
237
|
+
sage: foo(7, what='Hello')
|
|
238
|
+
doctest:...: FutureWarning: This class/method/function is
|
|
239
|
+
marked as experimental. It, its functionality or its
|
|
240
|
+
interface might change without a formal deprecation.
|
|
241
|
+
See https://github.com/sagemath/sage/issues/79997 for details.
|
|
242
|
+
(7,) {'what': 'Hello'}
|
|
243
|
+
|
|
244
|
+
::
|
|
245
|
+
|
|
246
|
+
sage: class bird(SageObject):
|
|
247
|
+
....: @sage.misc.superseded.experimental(issue_number=99999)
|
|
248
|
+
....: def __init__(self, *args, **kwargs):
|
|
249
|
+
....: print("piep {} {}".format(args, kwargs))
|
|
250
|
+
sage: _ = bird(99)
|
|
251
|
+
doctest:...: FutureWarning: This class/method/function is
|
|
252
|
+
marked as experimental. It, its functionality or its
|
|
253
|
+
interface might change without a formal deprecation.
|
|
254
|
+
See https://github.com/sagemath/sage/issues/99999 for details.
|
|
255
|
+
piep (99,) {}
|
|
256
|
+
|
|
257
|
+
TESTS:
|
|
258
|
+
|
|
259
|
+
The following test works together with the doc-test for
|
|
260
|
+
:meth:`__experimental_self_test` to demonstrate that warnings are issued only
|
|
261
|
+
once, even in doc-tests (see :issue:`20601`).
|
|
262
|
+
::
|
|
263
|
+
|
|
264
|
+
sage: from sage.misc.superseded import __experimental_self_test
|
|
265
|
+
sage: _ = __experimental_self_test("A")
|
|
266
|
+
doctest:...: FutureWarning: This class/method/function is
|
|
267
|
+
marked as experimental. It, its functionality or its
|
|
268
|
+
interface might change without a formal deprecation.
|
|
269
|
+
See https://github.com/sagemath/sage/issues/88888 for details.
|
|
270
|
+
I'm A
|
|
271
|
+
|
|
272
|
+
.. SEEALSO::
|
|
273
|
+
|
|
274
|
+
:func:`experimental`,
|
|
275
|
+
:func:`warning`,
|
|
276
|
+
:func:`deprecation`.
|
|
277
|
+
"""
|
|
278
|
+
self.issue_number = issue_number
|
|
279
|
+
self.stacklevel = stacklevel
|
|
280
|
+
|
|
281
|
+
def __call__(self, func):
|
|
282
|
+
"""
|
|
283
|
+
Print experimental warning.
|
|
284
|
+
|
|
285
|
+
INPUT:
|
|
286
|
+
|
|
287
|
+
- ``func`` -- the function to decorate
|
|
288
|
+
|
|
289
|
+
OUTPUT: the wrapper to this function
|
|
290
|
+
|
|
291
|
+
TESTS::
|
|
292
|
+
|
|
293
|
+
sage: def foo(*args, **kwargs):
|
|
294
|
+
....: print("{} {}".format(args, kwargs))
|
|
295
|
+
sage: from sage.misc.superseded import experimental
|
|
296
|
+
sage: ex_foo = experimental(issue_number=99399)(foo)
|
|
297
|
+
sage: ex_foo(3, what='Hello')
|
|
298
|
+
doctest:...: FutureWarning: This class/method/function is
|
|
299
|
+
marked as experimental. It, its functionality or its
|
|
300
|
+
interface might change without a formal deprecation.
|
|
301
|
+
See https://github.com/sagemath/sage/issues/99399 for details.
|
|
302
|
+
(3,) {'what': 'Hello'}
|
|
303
|
+
"""
|
|
304
|
+
from sage.misc.decorators import sage_wraps
|
|
305
|
+
|
|
306
|
+
@sage_wraps(func)
|
|
307
|
+
def wrapper(*args, **kwds):
|
|
308
|
+
if not wrapper._already_issued:
|
|
309
|
+
experimental_warning(self.issue_number,
|
|
310
|
+
'This class/method/function is marked as '
|
|
311
|
+
'experimental. It, its functionality or its '
|
|
312
|
+
'interface might change without a '
|
|
313
|
+
'formal deprecation.',
|
|
314
|
+
self.stacklevel)
|
|
315
|
+
wrapper._already_issued = True
|
|
316
|
+
return func(*args, **kwds)
|
|
317
|
+
wrapper._already_issued = False
|
|
318
|
+
|
|
319
|
+
return wrapper
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
class __experimental_self_test:
|
|
323
|
+
r"""
|
|
324
|
+
This is a class only to demonstrate with a doc-test that the @experimental
|
|
325
|
+
decorator only issues a warning message once (see :issue:`20601`).
|
|
326
|
+
|
|
327
|
+
The test below does not issue a warning message because that warning has
|
|
328
|
+
already been issued by a previous doc-test in the @experimental code. Note
|
|
329
|
+
that this behaviour cannot be demonstrated within a single documentation
|
|
330
|
+
string: Sphinx will itself suppress multiple issued warnings.
|
|
331
|
+
|
|
332
|
+
TESTS::
|
|
333
|
+
|
|
334
|
+
sage: from sage.misc.superseded import __experimental_self_test
|
|
335
|
+
sage: _ = __experimental_self_test("B")
|
|
336
|
+
I'm B
|
|
337
|
+
"""
|
|
338
|
+
@experimental(issue_number=88888)
|
|
339
|
+
def __init__(self, x):
|
|
340
|
+
print("I'm " + x)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
class DeprecatedFunctionAlias:
|
|
344
|
+
"""
|
|
345
|
+
A wrapper around methods or functions which automatically prints a
|
|
346
|
+
deprecation message. See :func:`deprecated_function_alias`.
|
|
347
|
+
|
|
348
|
+
AUTHORS:
|
|
349
|
+
|
|
350
|
+
- Florent Hivert (2009-11-23), with the help of Mike Hansen.
|
|
351
|
+
- Luca De Feo (2011-07-11), printing the full module path when different from old path
|
|
352
|
+
"""
|
|
353
|
+
def __init__(self, issue_number, func, module, instance=None, unbound=None):
|
|
354
|
+
r"""
|
|
355
|
+
TESTS::
|
|
356
|
+
|
|
357
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
358
|
+
sage: g = deprecated_function_alias(13109, number_of_partitions)
|
|
359
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
360
|
+
sage: g.__doc__
|
|
361
|
+
'Deprecated: Use :func:`number_of_partitions` instead.\nSee :issue:`13109` for details.\n\n'
|
|
362
|
+
"""
|
|
363
|
+
_check_issue_number(issue_number)
|
|
364
|
+
try:
|
|
365
|
+
self.__dict__.update(func.__dict__)
|
|
366
|
+
except AttributeError:
|
|
367
|
+
pass # Cython classes don't have __dict__
|
|
368
|
+
self.func = func
|
|
369
|
+
self.issue_number = issue_number
|
|
370
|
+
self.instance = instance # for use with methods
|
|
371
|
+
self.unbound = unbound
|
|
372
|
+
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'
|
|
380
|
+
self.__doc__ = doc
|
|
381
|
+
|
|
382
|
+
@lazy_attribute
|
|
383
|
+
def __name__(self):
|
|
384
|
+
r"""
|
|
385
|
+
TESTS::
|
|
386
|
+
|
|
387
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
388
|
+
sage: g = deprecated_function_alias(13109, number_of_partitions)
|
|
389
|
+
sage: g.__name__
|
|
390
|
+
'g'
|
|
391
|
+
|
|
392
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
393
|
+
sage: class cls():
|
|
394
|
+
....: def new_meth(self): return 42
|
|
395
|
+
....: old_meth = deprecated_function_alias(13109, new_meth)
|
|
396
|
+
sage: cls.old_meth.__name__
|
|
397
|
+
'old_meth'
|
|
398
|
+
sage: cls().old_meth.__name__
|
|
399
|
+
'old_meth'
|
|
400
|
+
|
|
401
|
+
sage: cython('\n'.join([ # needs sage.misc.cython
|
|
402
|
+
....: r"from sage.misc.superseded import deprecated_function_alias",
|
|
403
|
+
....: r"cdef class cython_cls():",
|
|
404
|
+
....: r" def new_cython_meth(self):",
|
|
405
|
+
....: r" return 1",
|
|
406
|
+
....: r" old_cython_meth = deprecated_function_alias(13109, new_cython_meth)"
|
|
407
|
+
....: ]))
|
|
408
|
+
sage: cython_cls().old_cython_meth.__name__ # needs sage.misc.cython
|
|
409
|
+
'old_cython_meth'
|
|
410
|
+
"""
|
|
411
|
+
# first look through variables in stack frames
|
|
412
|
+
for frame in inspect.stack():
|
|
413
|
+
for name, obj in frame[0].f_globals.items():
|
|
414
|
+
if obj is self:
|
|
415
|
+
return name
|
|
416
|
+
# then search object that contains self as method
|
|
417
|
+
import gc
|
|
418
|
+
import copy
|
|
419
|
+
gc.collect()
|
|
420
|
+
|
|
421
|
+
def is_class(gc_ref):
|
|
422
|
+
if not isinstance(gc_ref, dict):
|
|
423
|
+
return False
|
|
424
|
+
is_python_class = '__module__' in gc_ref or '__package__' in gc_ref
|
|
425
|
+
is_cython_class = '__new__' in gc_ref
|
|
426
|
+
return is_python_class or is_cython_class
|
|
427
|
+
search_for = self if (self.unbound is None) else self.unbound
|
|
428
|
+
for ref in gc.get_referrers(search_for):
|
|
429
|
+
if is_class(ref) and ref is not self.__dict__:
|
|
430
|
+
ref_copy = copy.copy(ref)
|
|
431
|
+
for key, val in ref_copy.items():
|
|
432
|
+
if val is search_for:
|
|
433
|
+
return key
|
|
434
|
+
raise AttributeError("The name of this deprecated function cannot be determined")
|
|
435
|
+
|
|
436
|
+
def __call__(self, *args, **kwds):
|
|
437
|
+
"""
|
|
438
|
+
TESTS::
|
|
439
|
+
|
|
440
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
441
|
+
sage: def bla(): return 42
|
|
442
|
+
sage: blo = deprecated_function_alias(13109, bla)
|
|
443
|
+
sage: blo()
|
|
444
|
+
doctest:...: DeprecationWarning: blo is deprecated. Please use bla instead.
|
|
445
|
+
See https://github.com/sagemath/sage/issues/13109 for details.
|
|
446
|
+
42
|
|
447
|
+
"""
|
|
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__
|
|
452
|
+
|
|
453
|
+
deprecation(self.issue_number,
|
|
454
|
+
"{} is deprecated. Please use {} instead.".format(
|
|
455
|
+
self.__name__, other))
|
|
456
|
+
if self.instance is None:
|
|
457
|
+
return self.func(*args, **kwds)
|
|
458
|
+
else:
|
|
459
|
+
return self.func(self.instance, *args, **kwds)
|
|
460
|
+
|
|
461
|
+
def __get__(self, inst, cls=None):
|
|
462
|
+
"""
|
|
463
|
+
TESTS::
|
|
464
|
+
|
|
465
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
466
|
+
sage: class cls():
|
|
467
|
+
....: def new_meth(self): return 42
|
|
468
|
+
....: old_meth = deprecated_function_alias(13109, new_meth)
|
|
469
|
+
sage: obj = cls()
|
|
470
|
+
sage: obj.old_meth.instance is obj
|
|
471
|
+
True
|
|
472
|
+
|
|
473
|
+
:issue:`19125`::
|
|
474
|
+
|
|
475
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
476
|
+
sage: class A:
|
|
477
|
+
....: def __init__(self, x):
|
|
478
|
+
....: self.x = x
|
|
479
|
+
....: def f(self, y):
|
|
480
|
+
....: return self.x+y
|
|
481
|
+
....: g = deprecated_function_alias(42, f)
|
|
482
|
+
sage: a1 = A(1)
|
|
483
|
+
sage: a2 = A(2)
|
|
484
|
+
sage: a1.g(a2.g(0))
|
|
485
|
+
doctest:...: DeprecationWarning: g is deprecated. Please use f instead.
|
|
486
|
+
See https://github.com/sagemath/sage/issues/42 for details.
|
|
487
|
+
3
|
|
488
|
+
sage: a1.f(a2.f(0))
|
|
489
|
+
3
|
|
490
|
+
"""
|
|
491
|
+
if inst is None:
|
|
492
|
+
return self # Unbound method lookup on class
|
|
493
|
+
else:
|
|
494
|
+
# Return a bound method wrapper
|
|
495
|
+
return DeprecatedFunctionAlias(self.issue_number, self.func,
|
|
496
|
+
self.__module__, instance=inst,
|
|
497
|
+
unbound=self)
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def deprecated_function_alias(issue_number, func):
|
|
501
|
+
"""
|
|
502
|
+
Create an aliased version of a function or a method which raises a
|
|
503
|
+
deprecation warning message.
|
|
504
|
+
|
|
505
|
+
If f is a function or a method, write
|
|
506
|
+
``g = deprecated_function_alias(issue_number, f)``
|
|
507
|
+
to make a deprecated aliased version of f.
|
|
508
|
+
|
|
509
|
+
INPUT:
|
|
510
|
+
|
|
511
|
+
- ``issue_number`` -- integer; the github issue number where the
|
|
512
|
+
deprecation is introduced
|
|
513
|
+
|
|
514
|
+
- ``func`` -- the function or method to be aliased
|
|
515
|
+
|
|
516
|
+
EXAMPLES::
|
|
517
|
+
|
|
518
|
+
sage: from sage.misc.superseded import deprecated_function_alias
|
|
519
|
+
sage: g = deprecated_function_alias(13109, number_of_partitions) # needs sage.combinat sage.libs.flint
|
|
520
|
+
sage: g(5) # needs sage.combinat sage.libs.flint
|
|
521
|
+
doctest:...: DeprecationWarning: g is deprecated.
|
|
522
|
+
Please use sage.combinat.partition.number_of_partitions instead.
|
|
523
|
+
See https://github.com/sagemath/sage/issues/13109 for details.
|
|
524
|
+
7
|
|
525
|
+
|
|
526
|
+
This also works for methods::
|
|
527
|
+
|
|
528
|
+
sage: class cls():
|
|
529
|
+
....: def new_meth(self): return 42
|
|
530
|
+
....: old_meth = deprecated_function_alias(13109, new_meth)
|
|
531
|
+
sage: cls().old_meth()
|
|
532
|
+
doctest:...: DeprecationWarning: old_meth is deprecated. Please use new_meth instead.
|
|
533
|
+
See https://github.com/sagemath/sage/issues/13109 for details.
|
|
534
|
+
42
|
|
535
|
+
|
|
536
|
+
:issue:`11585`::
|
|
537
|
+
|
|
538
|
+
sage: def a(): pass
|
|
539
|
+
sage: b = deprecated_function_alias(13109, a)
|
|
540
|
+
sage: b()
|
|
541
|
+
doctest:...: DeprecationWarning: b is deprecated. Please use a instead.
|
|
542
|
+
See https://github.com/sagemath/sage/issues/13109 for details.
|
|
543
|
+
|
|
544
|
+
AUTHORS:
|
|
545
|
+
|
|
546
|
+
- Florent Hivert (2009-11-23), with the help of Mike Hansen.
|
|
547
|
+
- Luca De Feo (2011-07-11), printing the full module path when different from old path
|
|
548
|
+
"""
|
|
549
|
+
module_name = None
|
|
550
|
+
frame0 = inspect.currentframe()
|
|
551
|
+
if frame0:
|
|
552
|
+
frame1 = frame0.f_back
|
|
553
|
+
if frame1:
|
|
554
|
+
module_name = inspect.getmodulename(frame1.f_code.co_filename)
|
|
555
|
+
if module_name is None:
|
|
556
|
+
module_name = '__main__'
|
|
557
|
+
return DeprecatedFunctionAlias(issue_number, func, module_name)
|