[Cython] Implementing tp_richcmp using __eq__ etc.

Emmanuel Gil Peyrot linkmauve at linkmauve.fr
Mon Nov 30 20:12:32 EST 2015


Hello,

I’m trying to implement the compilation of __eq__, __ne__, etc. in
extension types, to have them available in pure mode (see ticket #130).

I currently have an implementation which basically pastes the
body.stats from those six functions in a __richcmp__ one using a
template, but I find that very inelegant, as it removes the information
about the original location of this code which is very bad for
debugging, forces all six (or less) functions to use the same argument
names (or rename them), and probably some other issues.

So my idea was to convert each of those special function into a
CFuncDefNode from a DefNode, in order to remove the Python wrapper,
then to implement the new tp_richcmp slot as an util function directly
in C.

If this plan is sound, I’d like a few more informations, for now mostly
about the DefNode to CFuncDefNode conversion, which I’ve been unable to
do programmatically, with some later passes complaining about missing
base_type or declarator properties.  The next question is about
determining in the C code whether a specific method exists, and
otherwise returning NotImplemented instead.

Thanks for listening, I’m not sure I’ve been very understandable, I’m
still quite confused. ^^'

-- 
Emmanuel Gil Peyrot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20151201/3445c448/attachment.sig>


More information about the cython-devel mailing list