Hi Jeroen,

On 2015-03-04, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote:
> On 2015-03-04 14:14, Simon King wrote:
>> "Priority" in the sense of "if you want to implement comparison for
>> elements, then implement "_cmp_" rather than "__cmp__"?
> Yes. In other words: if a Python class has both __cmp__ and _cmp_, the 
> coercion framework should call _cmp_ (which will default to __cmp__).
>
> This would make _cmp_ analogous to other operators like _add_. The only 
> difference is that __cmp__ doesn't inherit if __hash__ is defined, so 
> you might need to define both __cmp__ and _cmp_.

I don't agree with that description. If a Python class has both __cmp__
and _cmp_ (or both __add__ and _add_), then of course __cmp__ (resp.
__add__) are called.

What *should* be the case (and I guess it is what you mean): If one
implements comparison for an element in Python, then one must not
override sage.structure.element.Element.__cmp__. Instead, one should
implement _cmp_ (which ought to be a cpdef method).

But wouldn't we still have the complication for Cython classes, that one
has to actually *copy* code from sage.structure.element.Element? If I
recall correctly, this is needed in order to create hashable elements
(if you override __hash__ then you must also override __cmp__). That
said, this could be resolved in the same way: We should *never* override
sage.structure.element.Element.__hash__. Instead, the generic __hash__
method should call _hash_.

By consequence, it would not be needed any longer to copy the generic
code, since neither __hash__ nor __cmp__ would be overridden (only
_hash_ and _cmp_ are).

Best regards,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to