From ffc7371eb9c3ff84e575cf3d31000ce3bd3ee2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20R=C3=BCth?= Date: Fri, 21 Jul 2017 17:43:14 -0500 Subject: [PATCH] Revert "Remove obsolete type checks" This reverts commit b6ef396f00e8cde354385ded5a9e36934c2016b9. Jeroen noted: Sorry, I was wrong. At least some of the type checks are still needed, because equal parents does not imply equal types here. For example: ``` sage: R. = PolynomialRing(QQ, 2) sage: S. = R.quo(x^2 + y^2) sage: phi = S.cover() sage: alpha = R.hom(R, (0,0)) sage: psi = phi.pre_compose(alpha) sage: parent(psi) is parent(phi) True sage: type(psi) is type(phi) True ``` --- src/sage/rings/morphism.pyx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 9f9944b29e0..c5e8be448f5 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -524,6 +524,9 @@ cdef class RingMap_lift(RingMap): if op not in [Py_EQ, Py_NE]: return NotImplemented + if not isinstance(other, RingMap_lift): + return (op == Py_NE) + # Since they are lifting maps they are determined by their # parents, i.e., by the domain and codomain, since we just # compare those. @@ -959,6 +962,9 @@ cdef class RingHomomorphism_coercion(RingHomomorphism): if op not in [Py_EQ, Py_NE]: return NotImplemented + if not isinstance(other, RingHomomorphism_coercion): + return (op == Py_NE) + # Since they are coercion morphisms they are determined by # their parents, i.e., by the domain and codomain, so we just # compare those. @@ -1171,6 +1177,11 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): sage: loads(dumps(f2)) == f2 True """ + if not isinstance(other, RingHomomorphism_im_gens): + if op in [Py_EQ, Py_NE]: + return (op == Py_NE) + return NotImplemented + return richcmp(self.__im_gens, (other).__im_gens, op) def __hash__(self): @@ -1460,6 +1471,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: f1M == loads(dumps(f1M)) True """ + if not isinstance(other, RingHomomorphism_from_base): + if op in [Py_EQ, Py_NE]: + return (op == Py_NE) + return NotImplemented return richcmp(self.__underlying, (other).__underlying, op) def _repr_defn(self): @@ -1635,6 +1650,9 @@ cdef class RingHomomorphism_cover(RingHomomorphism): if op not in [Py_EQ, Py_NE]: return NotImplemented + if not isinstance(other, RingHomomorphism_cover): + return (op == Py_NE) + return richcmp(self.parent(), other.parent(), op) def __hash__(self): @@ -1831,6 +1849,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): if op not in [Py_EQ, Py_NE]: return NotImplemented + if not isinstance(other, RingHomomorphism_from_quotient): + return (op == Py_NE) + cdef RingHomomorphism_from_quotient left = self cdef RingHomomorphism_from_quotient right = other return richcmp(left.phi, right.phi, op)