Hi Antoine, I have a lot of troubles to reminder how Python converts numbers, I collected notes about the Python "number tower" and the C implementation: https://pythondev.readthedocs.io/numbers.html
Honestly, I don't understand well the difference between __int__() and __index__(). * https://docs.python.org/dev/reference/datamodel.html#object.__int__ * https://docs.python.org/dev/reference/datamodel.html#object.__index__ Victor On Wed, Oct 13, 2021 at 7:11 PM Antoine Pitrou <anto...@python.org> wrote: > > > 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 -- python-dev@python.org > To unsubscribe send an email to python-dev-le...@python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev@python.org/message/K6TEYMDY5NEDV4MHH6EGIOQWDOAKSPJV/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Night gathers, and now my watch begins. It shall not end until my death. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/QFMFPMCSDWV7S5QGPYS7K2VN4CHF5KDL/ Code of Conduct: http://python.org/psf/codeofconduct/