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

Commit

Permalink
Reverting to previous behavior of allowing comparison of equal parents.
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Scrimshaw committed Aug 29, 2016
1 parent 7f8d438 commit ebcd19f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/sage/structure/element_wrapper.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from sage.structure.element cimport Element
cdef class ElementWrapper(Element):
cdef public object value

cpdef _richcmp_(left, right, int op)
cpdef bint _lt_by_value(self, other)
cpdef int _cmp_by_value(self, other)

Expand Down
36 changes: 31 additions & 5 deletions src/sage/structure/element_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ AUTHORS:
from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE

from sage.structure.parent cimport Parent
from sage.structure.element cimport Element
from sage.structure.element cimport Element, coercion_model
from copy import copy

cdef class ElementWrapper(Element):
Expand Down Expand Up @@ -248,12 +248,12 @@ cdef class ElementWrapper(Element):
"""
return hash(self.value)

cpdef _richcmp_(left, right, int op):
def __richcmp__(left, right, int op):
"""
Return ``True`` if ``left`` compares with ``right`` based on ``op``.
Default implementation of ``self == other``: two elements are
equal if they have the same class, same parent, and same value.
equal if they have equal parents and equal values.
Default implementation of ``self < other``: two elements are
always incomparable.
Expand All @@ -266,6 +266,33 @@ cdef class ElementWrapper(Element):
TESTS:
Check that elements of equal-but-not-identical parents compare
properly (see :trac:`19488`)::
sage: from sage.misc.nested_class_test import TestParent4
sage: P = TestParent4()
sage: Q = TestParent4()
sage: P == Q
True
sage: P is Q
False
sage: x = P.an_element(); x
'_an_element_'
sage: y = Q.an_element(); y
'_an_element_'
sage: x == y
True
"""
if isinstance(right, ElementWrapper) and left.parent() == right.parent():
return left._richcmp_(right, op)
return coercion_model.richcmp(left, right, op)

cpdef _richcmp_(left, right, int op):
"""
Return ``True`` if ``left`` compares with ``right`` based on ``op``.
TESTS:
Testing equality::
sage: from sage.structure.element_wrapper import DummyParent
Expand Down Expand Up @@ -317,8 +344,7 @@ cdef class ElementWrapper(Element):
sage: sorted([y,x])
[2, 1]
"""
cdef ElementWrapper self
self = left
cdef ElementWrapper self = left
if op == Py_EQ or op == Py_LE or op == Py_GE:
return self.value == (<ElementWrapper>right).value
if op == Py_NE:
Expand Down

0 comments on commit ebcd19f

Please sign in to comment.