From 0e15a9e63d86091692fff04c925ae16a95b6362d Mon Sep 17 00:00:00 2001 From: Xavier Caruso Date: Thu, 16 Apr 2020 11:15:34 +0200 Subject: [PATCH] better test in register_coercion --- src/sage/structure/parent.pyx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 129f2a264f5..eb0255bf171 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -1555,6 +1555,18 @@ cdef class Parent(sage.structure.category_object.CategoryObject): Traceback (most recent call last): ... AssertionError: coercion from Univariate Polynomial Ring in b over Integer Ring to Univariate Polynomial Ring in a over Integer Ring already registered or discovered + + TESTS: + + We check that :trac:`29517` has been fixed:: + + sage: A. = ZZ[] + sage: B. = ZZ[] + sage: B.has_coerce_map_from(A) + False + sage: B.register_coercion(A.hom([y])) + sage: x + y + 2*y """ if isinstance(mor, map.Map): if mor.codomain() is not self: @@ -1565,7 +1577,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): raise TypeError("coercions must be parents or maps (got %s)" % type(mor)) D = mor.domain() - assert not (self._coercions_used and D in self._coerce_from_hash), "coercion from {} to {} already registered or discovered".format(D, self) + assert not (self._coercions_used and D in self._coerce_from_hash and + self._coerce_from_hash.get(D) is not None), "coercion from {} to {} already registered or discovered".format(D, self) mor._is_coercion = True self._coerce_from_list.append(mor) self._registered_domains.append(D)