From 2ee2abf22f8bf06995c2ce0fb70f365cba8055d8 Mon Sep 17 00:00:00 2001 From: Julian Rueth Date: Wed, 19 Jul 2017 23:36:33 +0000 Subject: [PATCH 1/3] Do not override __richcmp__ in Ring morphisms --- src/sage/rings/morphism.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 978fe442e81..c5e8be448f5 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -499,7 +499,7 @@ cdef class RingMap_lift(RingMap): _slots['S'] = self.S return Morphism._extra_slots(self, _slots) - def __richcmp__(self, other, int op): + def _richcmp_(self, other, int op): """ Compare a ring lifting maps ``self`` to ``other``. @@ -940,7 +940,7 @@ cdef class RingHomomorphism_coercion(RingHomomorphism): """ return "Ring Coercion" - def __richcmp__(self, other, int op): + def _richcmp_(self, other, int op): """ Compare a ring coercion morphism ``self`` to ``other``. @@ -1633,7 +1633,7 @@ cdef class RingHomomorphism_cover(RingHomomorphism): """ return self.codomain().defining_ideal() - def __richcmp__(self, other, int op): + def _richcmp_(self, other, int op): """ Compare ``self`` to ``other``. @@ -1830,7 +1830,7 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): """ return self.phi - def __richcmp__(self, other, op): + def _richcmp_(self, other, op): """ Compare ``self`` to ``other``. From b6ef396f00e8cde354385ded5a9e36934c2016b9 Mon Sep 17 00:00:00 2001 From: Julian Rueth Date: Thu, 20 Jul 2017 21:29:15 +0000 Subject: [PATCH 2/3] Remove obsolete type checks --- src/sage/rings/morphism.pyx | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index c5e8be448f5..9f9944b29e0 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -524,9 +524,6 @@ 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. @@ -962,9 +959,6 @@ 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. @@ -1177,11 +1171,6 @@ 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): @@ -1471,10 +1460,6 @@ 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): @@ -1650,9 +1635,6 @@ 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): @@ -1849,9 +1831,6 @@ 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) 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 3/3] 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)