diff --git a/src/sage/misc/functional.py b/src/sage/misc/functional.py index 09d1b05ced9..4c9b9f5683d 100644 --- a/src/sage/misc/functional.py +++ b/src/sage/misc/functional.py @@ -184,7 +184,7 @@ def coerce(P, x): """ try: - return P._coerce_(x) + return P.coerce(x) except AttributeError: return P(x) diff --git a/src/sage/quadratic_forms/quadratic_form__evaluate.pyx b/src/sage/quadratic_forms/quadratic_form__evaluate.pyx index 9ee823da68f..01e9094786f 100644 --- a/src/sage/quadratic_forms/quadratic_form__evaluate.pyx +++ b/src/sage/quadratic_forms/quadratic_form__evaluate.pyx @@ -60,7 +60,7 @@ cdef QFEvaluateVector_cdef(Q, v): tmp_val += Q[i,j] * v[i] * v[j] ## Return the value (over R) - return Q.base_ring()._coerce_(tmp_val) + return Q.base_ring().coerce(tmp_val) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index c536023076d..5cd5cb1910f 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -415,9 +415,9 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): EXAMPLES:: - sage: CDF._coerce_(5) # indirect doctest + sage: CDF.coerce(5) # indirect doctest 5.0 - sage: CDF._coerce_(RDF(3.4)) + sage: CDF.coerce(RDF(3.4)) 3.4 Thus the sum of a CDF and a symbolic object is symbolic:: diff --git a/src/sage/rings/finite_rings/element_pari_ffelt.pyx b/src/sage/rings/finite_rings/element_pari_ffelt.pyx index efb07d9089b..ee0f9b3c4f5 100644 --- a/src/sage/rings/finite_rings/element_pari_ffelt.pyx +++ b/src/sage/rings/finite_rings/element_pari_ffelt.pyx @@ -1272,7 +1272,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement): You can specify the instance of the Gap interpreter that is used:: sage: F = FiniteField(next_prime(200)^2, 'a', impl='pari_ffelt') - sage: a = F.multiplicative_generator () + sage: a = F.multiplicative_generator() sage: a._gap_ (gap) Z(211^2) sage: (a^20)._gap_(gap) @@ -1281,11 +1281,15 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement): Gap only supports relatively small finite fields:: sage: F = FiniteField(next_prime(1000)^2, 'a', impl='pari_ffelt') - sage: a = F.multiplicative_generator () - sage: gap._coerce_(a) + sage: a = F.multiplicative_generator() + sage: a._gap_init_() Traceback (most recent call last): ... TypeError: order must be at most 65536 + sage: gap.coerce(a) + Traceback (most recent call last): + ... + TypeError: no canonical coercion from Finite Field in a of size 1009^2 to Gap """ F = self._parent if F.order() > 65536: diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index c0a3406282f..582f59971f6 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -1311,26 +1311,26 @@ cdef class FiniteField(Field): a + 1 sage: k = GF(4, 'a') - sage: k._coerce_(GF(2)(1)) + sage: k.coerce(GF(2)(1)) 1 - sage: k._coerce_(k.0) + sage: k.coerce(k.0) a - sage: k._coerce_(3) + sage: k.coerce(3) 1 - sage: k._coerce_(2/3) + sage: k.coerce(2/3) Traceback (most recent call last): ... TypeError: no canonical coercion from Rational Field to Finite Field in a of size 2^2 - sage: FiniteField(16)._coerce_(FiniteField(4).0) + sage: FiniteField(16).coerce(FiniteField(4).0) z4^2 + z4 - sage: FiniteField(8, 'a')._coerce_(FiniteField(4, 'a').0) + sage: FiniteField(8, 'a').coerce(FiniteField(4, 'a').0) Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field in a of size 2^2 to Finite Field in a of size 2^3 - sage: FiniteField(8, 'a')._coerce_(FiniteField(7, 'a')(2)) + sage: FiniteField(8, 'a').coerce(FiniteField(7, 'a')(2)) Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field of size 7 to Finite Field in a of size 2^3 diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index f8b9bacc4f6..1f9af3c5f49 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -462,7 +462,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): 2 """ # The generators are irrelevant (Zmod(n) is its own base), so we ignore base_map - return codomain._coerce_(self) + return codomain.coerce(self) def __mod__(self, modulus): """ diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index f444add73e2..40eb6413ff4 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -1242,7 +1242,7 @@ def _coerce_map_from_(self, S): sage: R = IntegerModRing(17) sage: a = R(3) - sage: b = R._coerce_(3) + sage: b = R.coerce(3) sage: b 3 sage: a==b @@ -1258,7 +1258,7 @@ def _coerce_map_from_(self, S): :: - sage: R._coerce_(2/3) + sage: R.coerce(2/3) Traceback (most recent call last): ... TypeError: no canonical coercion from Rational Field to Ring of integers modulo 17 diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 23f4fc7d325..91a835b3206 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -776,7 +776,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: n._im_gens_(R, [R(1)]) 7 """ - return codomain._coerce_(self) + return codomain.coerce(self) cdef _xor(Integer self, Integer other): cdef Integer x diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index cdc16abc594..a67f28e89ba 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -213,7 +213,7 @@ def _im_gens_(self, codomain, im_gens, base_map=None): """ n = self.parent().ngens() if n == 0: - return codomain._coerce_(self) + return codomain.coerce(self) y = codomain(0) if base_map is None: # Just use conversion diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 24718bbc1b5..d09ddf63c58 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -527,7 +527,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): We can coerce elements of self to self:: - sage: P._coerce_(x*y + 1/2) + sage: P.coerce(x*y + 1/2) x*y + 1/2 We can coerce elements for a ring with the same algebraic properties:: @@ -540,31 +540,31 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): sage: P is R False - sage: P._coerce_(x*y + 1) + sage: P.coerce(x*y + 1) x*y + 1 We can coerce base ring elements:: - sage: P._coerce_(3/2) + sage: P.coerce(3/2) 3/2 and all kinds of integers:: - sage: P._coerce_(ZZ(1)) + sage: P.coerce(ZZ(1)) 1 - sage: P._coerce_(int(1)) + sage: P.coerce(int(1)) 1 sage: k. = GF(2^8) sage: P. = PolynomialRing(k,2) - sage: P._coerce_(a) + sage: P.coerce(a) a sage: z = QQ['z'].0 sage: K. = NumberField(z^2 - 2) sage: P. = PolynomialRing(K, 2) - sage: P._coerce_(1/2*s) + sage: P.coerce(1/2*s) (1/2*s) TESTS:: @@ -988,7 +988,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): # we need to do this, to make sure that we actually get an # element in self. - return self._coerce_c(element) + return self.coerce(element) if hasattr(element,'_polynomial_'): # symbolic.expression.Expression return element._polynomial_(self) @@ -1598,9 +1598,9 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): cdef number *denom if self is not f._parent: - f = self._coerce_c(f) + f = self.coerce(f) if self is not g._parent: - g = self._coerce_c(g) + g = self.coerce(g) if not f._poly: return self._zero_element @@ -1653,7 +1653,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): cdef poly *_b cdef ring *_r if a._parent is not b._parent: - b = a._parent._coerce_c(b) + b = a._parent.coerce(b) _a = a._poly _b = b._poly @@ -1702,9 +1702,9 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): cdef poly *m = p_ISet(1,self._ring) if self is not f._parent: - f = self._coerce_c(f) + f = self.coerce(f) if self is not g._parent: - g = self._coerce_c(g) + g = self.coerce(g) if f._poly == NULL: if g._poly == NULL: @@ -1814,7 +1814,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): cdef poly *q if h._parent is not g._parent: - g = h._parent._coerce_c(g) + g = h._parent.coerce(g) r = h._parent_ring p = g._poly @@ -3532,7 +3532,7 @@ cdef class MPolynomial_libsingular(MPolynomial): p_Delete(&_p, _ring) raise TypeError("keys do not match self's parent") try: - v = parent._coerce_c(v) + v = parent.coerce(v) except TypeError: try_symbolic = 1 break @@ -3568,7 +3568,7 @@ cdef class MPolynomial_libsingular(MPolynomial): p_Delete(&_p, _ring) raise TypeError("key does not match") try: - v = parent._coerce_c(v) + v = parent.coerce(v) except TypeError: try_symbolic = 1 break @@ -4537,7 +4537,7 @@ cdef class MPolynomial_libsingular(MPolynomial): if not (isinstance(f,MPolynomial_libsingular) \ and (f)._parent is parent): try: - f = parent._coerce_c(f) + f = parent.coerce(f) except TypeError as msg: id_Delete(&fI,r) id_Delete(&_I,r) @@ -4664,7 +4664,7 @@ cdef class MPolynomial_libsingular(MPolynomial): if not (isinstance(f,MPolynomial_libsingular) \ and (f)._parent is parent): try: - f = parent._coerce_c(f) + f = parent.coerce(f) except TypeError as msg: id_Delete(&_I,r) raise TypeError(msg) @@ -4713,7 +4713,7 @@ cdef class MPolynomial_libsingular(MPolynomial): if not (isinstance(other,MPolynomial_libsingular) \ and (other)._parent is parent): try: - other = parent._coerce_c(other) + other = parent.coerce(other) except TypeError as msg: id_Delete(&_I,r) raise TypeError(msg) @@ -4899,7 +4899,7 @@ cdef class MPolynomial_libsingular(MPolynomial): raise TypeError("LCM over non-integral domains not available.") if self._parent is not g._parent: - _g = self._parent._coerce_c(g) + _g = self._parent.coerce(g) else: _g = g @@ -5052,9 +5052,9 @@ cdef class MPolynomial_libsingular(MPolynomial): cdef ring *r = self._parent_ring if not self._parent is m._parent: - m = self._parent._coerce_c(m) + m = self._parent.coerce(m) if not self._parent is q._parent: - q = self._parent._coerce_c(q) + q = self._parent.coerce(q) if m._poly and m._poly.next: raise ArithmeticError("m must be a monomial.") @@ -5140,9 +5140,9 @@ cdef class MPolynomial_libsingular(MPolynomial): cdef ring *r = self._parent_ring if not self._parent is m._parent: - m = self._parent._coerce_c(m) + m = self._parent.coerce(m) if not self._parent is q._parent: - q = self._parent._coerce_c(q) + q = self._parent.coerce(q) if m._poly and m._poly.next: raise ArithmeticError("m must be a monomial.") @@ -5219,7 +5219,7 @@ cdef class MPolynomial_libsingular(MPolynomial): #TODO: very slow n = self.parent().ngens() if n == 0: - return codomain._coerce_(self) + return codomain.coerce(self) y = codomain(0) if base_map is None: # Just use conversion diff --git a/src/sage/rings/polynomial/multi_polynomial_ring.py b/src/sage/rings/polynomial/multi_polynomial_ring.py index 88f7fc4ca51..adc5c87387d 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring.py +++ b/src/sage/rings/polynomial/multi_polynomial_ring.py @@ -234,7 +234,7 @@ def __call__(self, x=0, check=True): :: - sage: parent(S2._coerce_(S.0)) is S2 + sage: parent(S2.coerce(S.0)) is S2 True Conversion to reduce modulo a prime between rings with different @@ -415,7 +415,7 @@ def __call__(self, x=0, check=True): return self({self._zero_tuple: x}) try: - y = self.base_ring()._coerce_(x) + y = self.base_ring().coerce(x) return MPolynomial_polydict(self, {self._zero_tuple: y}) except TypeError: pass diff --git a/src/sage/rings/polynomial/pbori/pbori.pyx b/src/sage/rings/polynomial/pbori/pbori.pyx index 98afedfa785..decd7e20b1d 100644 --- a/src/sage/rings/polynomial/pbori/pbori.pyx +++ b/src/sage/rings/polynomial/pbori/pbori.pyx @@ -2731,7 +2731,7 @@ cdef class BooleanMonomial(MonoidElement): raise TypeError("BooleanMonomial.__add__ called with not supported types %s and %s" % (type(right), type(left))) res = new_BP_from_PBMonom(monom._ring, monom._pbmonom) - res += monom._ring._coerce_c(other) + res += monom._ring.coerce(other) return res def __floordiv__(BooleanMonomial left, right): @@ -3858,7 +3858,7 @@ cdef class BooleanPolynomial(MPolynomial): """ cdef BooleanPolynomialRing B = self._parent k = B._base - mon = B._coerce_c(mon) + mon = B.coerce(mon) if mon in set(self.set()): return k._one_element else: @@ -8161,9 +8161,9 @@ cdef class PolynomialFactory: elif isinstance(arg, BooleSet): return (arg)._ring._element_constructor_(arg) elif isinstance(arg, BooleanMonomial): - return (arg)._ring._coerce_(arg) + return (arg)._ring.coerce(arg) elif isinstance(ring, BooleanPolynomialRing): - return (ring)._coerce_(arg) + return (ring).coerce(arg) else: if isinstance(arg, int) or isinstance(arg, Integer): return new_BP_from_PBPoly(self._ring, diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index f1d8c02fa86..92e70f25343 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -551,7 +551,7 @@ cdef class NCPolynomialRing_plural(Ring): _p = p_NSet(_n, _ring) else: # fall back to base ring - element = base_ring._coerce_c(element) + element = base_ring.coerce(element) _n = sa2si(element,_ring) _p = p_NSet(_n, _ring) @@ -1060,9 +1060,9 @@ cdef class NCPolynomialRing_plural(Ring): cdef number *denom if self is not f._parent: - f = self._coerce_c(f) + f = self.coerce(f) if self is not g._parent: - g = self._coerce_c(g) + g = self.coerce(g) if(r != currRing): rChangeCurrRing(r) @@ -1128,7 +1128,7 @@ cdef class NCPolynomialRing_plural(Ring): cdef poly *_b cdef ring *_r if a._parent is not b._parent: - b = (a._parent)._coerce_c(b) + b = (a._parent).coerce(b) _a = a._poly _b = b._poly @@ -1189,9 +1189,9 @@ cdef class NCPolynomialRing_plural(Ring): cdef poly *m = p_ISet(1,self._ring) if self is not f._parent: - f = self._coerce_c(f) + f = self.coerce(f) if self is not g._parent: - g = self._coerce_c(g) + g = self.coerce(g) if f._poly == NULL: if g._poly == NULL: @@ -1324,7 +1324,7 @@ cdef class NCPolynomialRing_plural(Ring): cdef poly *q if h._parent is not g._parent: - g = (h._parent)._coerce_c(g) + g = (h._parent).coerce(g) r = (h._parent)._ring p = g._poly @@ -1793,7 +1793,7 @@ cdef class NCPolynomial_plural(RingElement): if not (isinstance(f, NCPolynomial_plural) \ and (f)._parent is parent): try: - f = parent._coerce_c(f) + f = parent.coerce(f) except TypeError as msg: id_Delete(&_I,r) raise TypeError(msg) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 76c6224c200..11849b388ea 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -2321,7 +2321,7 @@ cdef class Polynomial(CommutativeAlgebraElement): if isinstance(left, Polynomial): R = (left)._parent._base try: - x = R._coerce_(right) + x = R.coerce(right) return left * ~x except TypeError: pass @@ -11308,7 +11308,7 @@ cdef class Polynomial_generic_dense(Polynomial): if not self.__coeffs: return self if c._parent is not (self.__coeffs[0])._parent: - c = (self.__coeffs[0])._parent._coerce_c(c) + c = (self.__coeffs[0])._parent.coerce(c) v = [c * a for a in self.__coeffs] cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: @@ -11320,7 +11320,7 @@ cdef class Polynomial_generic_dense(Polynomial): if not self.__coeffs: return self if c._parent is not (self.__coeffs[0])._parent: - c = (self.__coeffs[0])._parent._coerce_c(c) + c = (self.__coeffs[0])._parent.coerce(c) v = [a * c for a in self.__coeffs] cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx index dd4e3eeaf22..41ddaa92e51 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx @@ -1136,7 +1136,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: r.parent() is ZZ True """ - cdef Polynomial_integer_dense_ntl _other = (self.parent()._coerce_(other)) + cdef Polynomial_integer_dense_ntl _other = (self.parent().coerce(other)) cdef ZZ_c* temp = ZZX_resultant(&self.__poly, &_other.__poly, proof) cdef Integer x = Integer.__new__(Integer) ZZ_to_mpz(x.value, temp) diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx index b6ccd29156e..2519b6e598d 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx @@ -872,7 +872,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): if do_sig: sig_off() else: if not isinstance(modulus, Polynomial_dense_modn_ntl_zz): - modulus = self.parent()._coerce_(modulus) + modulus = self.parent().coerce(modulus) zz_pX_Modulus_build(mod, (modulus).x) do_sig = zz_pX_deg(self.x) * e * self.c.p_bits > 1e5 @@ -1430,7 +1430,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): if do_sig: sig_off() else: if not isinstance(modulus, Polynomial_dense_modn_ntl_ZZ): - modulus = self.parent()._coerce_(modulus) + modulus = self.parent().coerce(modulus) ZZ_pX_Modulus_build(mod, (modulus).x) do_sig = ZZ_pX_deg(self.x) * e * self.c.p_bits > 1e5 @@ -1841,7 +1841,7 @@ cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): sage: r.parent() is GF(19) True """ - other = self.parent()._coerce_(other) + other = self.parent().coerce(other) return self.base_ring()(str(self.ntl_ZZ_pX().resultant(other.ntl_ZZ_pX()))) def discriminant(self): diff --git a/src/sage/rings/polynomial/polynomial_template.pxi b/src/sage/rings/polynomial/polynomial_template.pxi index d0da66e5067..959b5b38c8e 100644 --- a/src/sage/rings/polynomial/polynomial_template.pxi +++ b/src/sage/rings/polynomial/polynomial_template.pxi @@ -612,7 +612,7 @@ cdef class Polynomial_template(Polynomial): celement_pow(&r.x, &(self).x, e, NULL, (self)._cparent) else: if parent is not (modulus)._parent and parent != (modulus)._parent: - modulus = parent._coerce_(modulus) + modulus = parent.coerce(modulus) celement_pow(&r.x, &(self).x, e, &(modulus).x, (self)._cparent) #assert(r._parent(pari(self)**ee) == r) diff --git a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx index 65cb1a5d630..3fe6f33c18d 100644 --- a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx @@ -456,7 +456,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): NOTE: This function is a technology preview. It might disappear or be replaced without a deprecation warning. """ - cdef Polynomial_zmod_flint _other = self._parent._coerce_(other) + cdef Polynomial_zmod_flint _other = self._parent.coerce(other) cdef type t = type(self) cdef Polynomial_zmod_flint r = t.__new__(t) diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index 4a38cf4e6d2..0000a2daa38 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -867,24 +867,24 @@ def _coerce_impl(self, x): EXAMPLES:: sage: R. = PowerSeriesRing(ZZ) - sage: R._coerce_(t + t^2) # indirect doctest + sage: R.coerce(t + t^2) # indirect doctest t + t^2 - sage: R._coerce_(1/t) + sage: R.coerce(1/t) Traceback (most recent call last): ... TypeError: no canonical coercion from Laurent Series Ring in t over Rational Field to Power Series Ring in t over Integer Ring - sage: R._coerce_(5) + sage: R.coerce(5) 5 sage: tt = PolynomialRing(ZZ,'t').gen() - sage: R._coerce_(tt^2 + tt - 1) + sage: R.coerce(tt^2 + tt - 1) -1 + t + t^2 - sage: R._coerce_(1/2) + sage: R.coerce(1/2) Traceback (most recent call last): ... TypeError: no canonical coercion from Rational Field to Power Series Ring in t over Integer Ring sage: S. = PowerSeriesRing(ZZ) - sage: R._coerce_(s) + sage: R.coerce(s) Traceback (most recent call last): ... TypeError: no canonical coercion from Power Series Ring in s over Integer Ring to Power Series Ring in t over Integer Ring @@ -896,11 +896,11 @@ def _coerce_impl(self, x): sage: S = PowerSeriesRing(ZZ, 't') sage: f = S([1,2,3,4]); f 1 + 2*t + 3*t^2 + 4*t^3 - sage: g = R._coerce_(f); g + sage: g = R.coerce(f); g 1 + 2*t + 3*t^2 + 4*t^3 sage: parent(g) Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 - sage: S._coerce_(g) + sage: S.coerce(g) Traceback (most recent call last): ... TypeError: no canonical coercion from Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 to Power Series Ring in t over Integer Ring diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 0effcf381b0..72e87d0ff79 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -1258,7 +1258,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=False): False """ try: - return im_gens[0] == codomain._coerce_(self.gen(0)) + return im_gens[0] == codomain.coerce(self.gen(0)) except TypeError: return False diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index ff29c633824..3404edf4bfb 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -1118,7 +1118,7 @@ cdef class Rational(sage.structure.element.FieldElement): sage: a._im_gens_(QQ, [1/1]) -17/37 """ - return codomain._coerce_(self) + return codomain.coerce(self) def content(self, other): """ diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 7c447d4c7ff..50328384776 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -401,7 +401,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): False """ try: - return im_gens[0] == codomain._coerce_(self.gen(0)) + return im_gens[0] == codomain.coerce(self.gen(0)) except TypeError: return False diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 0743acd4ca7..1f01ff8ac55 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -959,7 +959,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): False """ try: - s = codomain._coerce_(self(1)) + s = codomain.coerce(self(1)) except TypeError: return False return s == im_gens[0] diff --git a/src/sage/structure/parent_base.pyx b/src/sage/structure/parent_base.pyx index deba26f1dbc..91c62424dae 100644 --- a/src/sage/structure/parent_base.pyx +++ b/src/sage/structure/parent_base.pyx @@ -10,6 +10,7 @@ Base class for old-style parent objects with a base ring # (at your option) any later version. # https://www.gnu.org/licenses/ # **************************************************************************** + cimport sage.structure.parent as parent from .coerce_exceptions import CoercionException @@ -28,6 +29,8 @@ cdef class ParentWithBase(Parent_old): cdef _coerce_c_impl(self,x): check_old_coerce(self) + from sage.misc.superseded import deprecation + deprecation(33497, "_coerce_c_impl is deprecated, use coerce instead") if not self._base is self: return self(self._base._coerce_(x)) else: @@ -38,3 +41,4 @@ cdef class ParentWithBase(Parent_old): check_old_coerce(self) raise CoercionException("BUG: the base_extend method must be defined for '%s' (class '%s')" % (self, type(self))) + diff --git a/src/sage/structure/parent_old.pyx b/src/sage/structure/parent_old.pyx index d8be438a21e..630f0ca8613 100644 --- a/src/sage/structure/parent_old.pyx +++ b/src/sage/structure/parent_old.pyx @@ -176,12 +176,16 @@ cdef class Parent(parent.Parent): def _coerce_(self, x): # Call this from Python (do not override!) if self._element_constructor is not None: + from sage.misc.superseded import deprecation + deprecation(33497, "_coerce_ is deprecated, use coerce instead") return self.coerce(x) check_old_coerce(self) return self._coerce_c(x) cpdef _coerce_c(self, x): # DO NOT OVERRIDE THIS (call it) if self._element_constructor is not None: + from sage.misc.superseded import deprecation + deprecation(33497, "_coerce_c is deprecated, use coerce instead") return self.coerce(x) check_old_coerce(self) try: diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 0fd0eeea6bd..c474d6d13e4 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -3786,7 +3786,7 @@ cdef class Expression(Expression_abc): try: return z except TypeError: - return self._parent._coerce_(z) + return self._parent.coerce(z) cpdef _add_(left, right): """ @@ -13788,7 +13788,7 @@ cpdef new_Expression_from_pyobject(parent, x, bint force=True, bint recursive=Tr if isinstance(x, Expression): return x try: - return parent._coerce_(x) + return parent.coerce(x) except TypeError: pass diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 05694e3b085..6cf7ade03f3 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -291,18 +291,18 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing): TESTS:: - sage: SR._coerce_(int(5)) + sage: SR.coerce(int(5)) 5 - sage: SR._coerce_(5) + sage: SR.coerce(5) 5 - sage: SR._coerce_(float(5)) + sage: SR.coerce(float(5)) 5.0 - sage: SR._coerce_(5.0) + sage: SR.coerce(5.0) 5.00000000000000 An interval arithmetic number:: - sage: SR._coerce_(RIF(pi)) + sage: SR.coerce(RIF(pi)) 3.141592653589794? The complex number `I`::