It seems a good idea to add __int__ to Fraction, but if you stop falling
back to __trunc__, won't that cause backwards compatibility issues? I'd say
looking for __trunc__ if the alternative is failing isn't so bad.
On Thu, Oct 31, 2019 at 3:43 AM Serhiy Storchaka
Currently __trunc__ is used for two purposes:
* In math.trunc() which just calls __trunc__. * In int() and PyNumber_Long() as a fallback if neither __int__ nor __index__ are implemented.
Unlike to __int__ and __index__ there is not a slot corresponding to __trunc__. So using it is slower than using __int__ or __index__. float and Decimal implement __int__ and __trunc__ by the same code. Only Fraction implements __trunc__ but not __int__.
I propose to deprecate the falling back to __trunc__ for converting to int and remove it in future. Fraction should implement __int__.
We cannot use __trunc__ for setting the nb_int slot because it can return non-int. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/6ZMQE4YT... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...