Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Revert "Remove obsolete type checks"
Browse files Browse the repository at this point in the history
This reverts commit b6ef396.

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.<x,y> = PolynomialRing(QQ, 2)
 sage: S.<a,b> = 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
```
  • Loading branch information
saraedum committed Jul 21, 2017
1 parent b6ef396 commit ffc7371
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sage/rings/morphism.pyx
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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, (<RingHomomorphism_im_gens>other).__im_gens, op)

def __hash__(self):
Expand Down Expand Up @@ -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, (<RingHomomorphism_from_base>other).__underlying, op)

def _repr_defn(self):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ffc7371

Please sign in to comment.