[Python-Dev] What is __int__ still useful for?

2021年10月13日 10:15:23 -0700

Hello,
It used to be that defining __int__ allowed an object to be accepted as
an integer from various functions, internal and third-party, thanks to
being implicitly called by e.g. PyLong_AsLong.
Today, and since bpo-37999, this is no longer the case. It seems that
__int__ has now become a strict equivalent to __trunc__. Of course,
user code can still look up and call the __int__ method explicitly (or
look up the nb_int slot, in C), but that's a bit of anti-pattern.
Is there a point in having three special methods __index__, __int__ and
__trunc__, if two are them are practically interchangeable?
Regards
Antoine.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/K6TEYMDY5NEDV4MHH6EGIOQWDOAKSPJV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to