Skip to content

Commit 8f23059

Browse files
author
Release Manager
committed
gh-40660: remove a deprecated class in structure as deprecated in #26879 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. URL: #40660 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents fa188af + dd34300 commit 8f23059

File tree

3 files changed

+18
-90
lines changed

3 files changed

+18
-90
lines changed

src/sage/structure/coerce_maps.pxd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
from sage.categories.map cimport Map
33

44

5-
cdef class DefaultConvertMap(Map):
6-
pass
7-
8-
9-
cdef class DefaultConvertMap_unique(DefaultConvertMap):
5+
cdef class DefaultConvertMap_unique(Map):
106
pass
117

128

src/sage/structure/coerce_maps.pyx

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ cdef object BuiltinMethodType = type(repr)
1414
cdef bint print_warnings = 0
1515

1616

17-
cdef class DefaultConvertMap(Map):
17+
cdef class DefaultConvertMap_unique(Map):
1818
"""
19-
This morphism simply calls the codomain's element_constructor method,
20-
passing in the codomain as the first argument.
21-
22-
EXAMPLES::
19+
This morphism simply defers action to the codomain's
20+
element_constructor method, WITHOUT passing in the codomain as the
21+
first argument.
2322
24-
sage: QQ[['x']].coerce_map_from(QQ)
25-
Coercion map:
26-
From: Rational Field
27-
To: Power Series Ring in x over Rational Field
23+
This is used for creating elements that don't take a parent as the
24+
first argument to their __init__ method, for example, Integers,
25+
Rationals, Algebraic Reals... all have a unique parent. It is also
26+
used when the element_constructor is a bound method (whose self
27+
argument is assumed to be bound to the codomain).
2828
"""
29-
def __init__(self, domain, codomain, category=None):
29+
def __init__(self, domain, codomain, category=None) -> None:
3030
"""
3131
TESTS:
3232

@@ -49,26 +49,7 @@ cdef class DefaultConvertMap(Map):
4949
False
5050
sage: QQ[['x']].coerce_map_from(QQ)._is_coercion
5151
True
52-
53-
This class is deprecated when used directly::
54-
55-
sage: from sage.structure.coerce_maps import DefaultConvertMap
56-
sage: DefaultConvertMap(ZZ, ZZ)
57-
doctest:...: DeprecationWarning: DefaultConvertMap is deprecated, use DefaultConvertMap_unique instead.
58-
This probably means that _element_constructor_ should be a method and not some other kind of callable
59-
See https://github.com/sagemath/sage/issues/26879 for details.
60-
Conversion map:
61-
From: Integer Ring
62-
To: Integer Ring
6352
"""
64-
# The base class DefaultConvertMap is deprecated, only the
65-
# derived class DefaultConvertMap_unique should be used.
66-
# When removing this deprecation, this class should be merged
67-
# into DefaultConvertMap_unique.
68-
if not isinstance(self, DefaultConvertMap_unique):
69-
from sage.misc.superseded import deprecation_cython as deprecation
70-
deprecation(26879, "DefaultConvertMap is deprecated, use DefaultConvertMap_unique instead. This probably means that _element_constructor_ should be a method and not some other kind of callable")
71-
7253
if not isinstance(domain, Parent):
7354
domain = Set_PythonType(domain)
7455
if category is None:
@@ -78,9 +59,9 @@ cdef class DefaultConvertMap(Map):
7859
Map.__init__(self, parent)
7960
self._coerce_cost = 100
8061
if (<Parent>codomain)._element_constructor is None:
81-
raise RuntimeError("BUG in coercion model, no element constructor for {}".format(type(codomain)))
62+
raise RuntimeError(f"BUG in coercion model, no element constructor for {type(codomain)}")
8263
83-
def _repr_type(self):
64+
def _repr_type(self) -> str:
8465
r"""
8566
Return a printable type for this morphism.
8667

@@ -104,7 +85,7 @@ cdef class DefaultConvertMap(Map):
10485
"""
10586
cdef Parent C = self._codomain
10687
try:
107-
return C._element_constructor(C, x)
88+
return C._element_constructor(x)
10889
except Exception:
10990
if print_warnings:
11091
print(type(C), C)
@@ -121,49 +102,6 @@ cdef class DefaultConvertMap(Map):
121102
sage: f(2/3, 4)
122103
2/3 + O(x^4)
123104
"""
124-
cdef Parent C = self._codomain
125-
try:
126-
if len(args) == 0:
127-
if len(kwds) == 0:
128-
# This line is apparently never used in any tests (hivert, 2009-04-28)
129-
return C._element_constructor(C, x)
130-
else:
131-
return C._element_constructor(C, x, **kwds)
132-
else:
133-
if len(kwds) == 0:
134-
return C._element_constructor(C, x, *args)
135-
else:
136-
return C._element_constructor(C, x, *args, **kwds)
137-
except Exception:
138-
if print_warnings:
139-
print(type(C), C)
140-
print(type(C._element_constructor), C._element_constructor)
141-
raise
142-
143-
144-
cdef class DefaultConvertMap_unique(DefaultConvertMap):
145-
"""
146-
This morphism simply defers action to the codomain's
147-
element_constructor method, WITHOUT passing in the codomain as the
148-
first argument.
149-
150-
This is used for creating elements that don't take a parent as the
151-
first argument to their __init__ method, for example, Integers,
152-
Rationals, Algebraic Reals... all have a unique parent. It is also
153-
used when the element_constructor is a bound method (whose self
154-
argument is assumed to be bound to the codomain).
155-
"""
156-
cpdef Element _call_(self, x):
157-
cdef Parent C = self._codomain
158-
try:
159-
return C._element_constructor(x)
160-
except Exception:
161-
if print_warnings:
162-
print(type(C), C)
163-
print(type(C._element_constructor), C._element_constructor)
164-
raise
165-
166-
cpdef Element _call_with_args(self, x, args=(), kwds={}):
167105
cdef Parent C = self._codomain
168106
try:
169107
if len(args) == 0:

src/sage/structure/parent.pyx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ from sage.structure.category_object import CategoryObject
124124
from sage.structure.coerce cimport coercion_model
125125
from sage.structure.coerce cimport parent_is_integers
126126
from sage.structure.coerce_exceptions import CoercionException
127-
from sage.structure.coerce_maps cimport (NamedConvertMap, DefaultConvertMap,
127+
from sage.structure.coerce_maps cimport (NamedConvertMap,
128128
DefaultConvertMap_unique, CallableConvertMap)
129129
from sage.structure.element cimport parent
130130

@@ -1939,8 +1939,7 @@ cdef class Parent(sage.structure.category_object.CategoryObject):
19391939
19401940
If a ``convert_method_name`` is provided, it creates a
19411941
``NamedConvertMap``, otherwise it creates a
1942-
``DefaultConvertMap`` or ``DefaultConvertMap_unique``
1943-
depending on whether or not init_no_parent is set.
1942+
``DefaultConvertMap_unique``.
19441943
19451944
EXAMPLES::
19461945
@@ -1969,11 +1968,7 @@ cdef class Parent(sage.structure.category_object.CategoryObject):
19691968
f = self.convert_method_map(S, m)
19701969
if f is not None:
19711970
return f
1972-
if self._element_init_pass_parent:
1973-
# deprecation(26879)
1974-
return DefaultConvertMap(S, self, category=category)
1975-
else:
1976-
return DefaultConvertMap_unique(S, self, category=category)
1971+
return DefaultConvertMap_unique(S, self, category=category)
19771972

19781973
def _convert_method_map(self, S, method_name=None):
19791974
"""
@@ -2274,7 +2269,6 @@ cdef class Parent(sage.structure.category_object.CategoryObject):
22742269
22752270
2. If ``self._coerce_map_from_(S)`` is not exactly one of
22762271
2277-
- DefaultConvertMap
22782272
- DefaultConvertMap_unique
22792273
- NamedConvertMap
22802274
@@ -2387,7 +2381,7 @@ cdef class Parent(sage.structure.category_object.CategoryObject):
23872381
best_mor = None
23882382
elif user_provided_mor is True:
23892383
best_mor = self._generic_coerce_map(S)
2390-
if not isinstance(best_mor, DefaultConvertMap):
2384+
if not isinstance(best_mor, DefaultConvertMap_unique):
23912385
return best_mor
23922386
# Continue searching for better maps. If there is something
23932387
# better in the list, return that instead. This is so, for

0 commit comments

Comments
 (0)