[Python-Dev] Do not fallback to __trunc__ when convert to int

2019年10月31日 03:43:35 -0700

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 -- [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/6ZMQE4YTFZWN7H366YJG5QFNP6TFPMFZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to