On Sun, Oct 26, 2014 at 2:50 PM, Nils Bruin <nbr...@sfu.ca> wrote:

> On Sunday, October 26, 2014 2:08:27 PM UTC-7, Volker Braun wrote:
>>
>> Python 3 only uses __eq__, __lt__, ..... Python also provides
>> functools.partial_ordering to synthesizing the remaining methods just from
>> __eq__ and __lt__. We either use that or write a similar decorator to also
>> deal with coercion.
>>
>> The __richcmp__ method is a Cython convention and doesn't exist in plain
>> Python 3 (or 2 for that matter).
>>
>
> A little more elaborately: On C-API level PyTypeObject has a
> tp_richcompare slot with the interface that cython's __richcompare__ has.
> Cython puts that special method in that slot for a cdef class. Python's
> "python" classes inherit a tp_richcompare that dispatches to __eq__ and
> __lt__ methods, probably because the constants Py_EQ etc. were deemed
> unappetizing to expose on python level.
>
> This also means that on cython level, we should stick with __richcompare__
> by default, because dispatching to __eq__ python functions would be slow.
>

I've been toying with the idea of letting (the default) __richcmp__
delegate to (c-level) __eq__, etc. if defined in Cython to further minimize
the differences between Cython and Python.

For elements, it'd be nice to have a them work with coercion by default,
with an _eq_ (and possibly _lt_) method that is guaranteed to get elements
of the same parent. There's the wrinkle that __richcmp__ and __hash__ must
be inherited together in the C API.

-- 
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