[issue36048] Deprecate implicit truncating when convert Python numbers to C integers: use __index__, not __int__

Serhiy Storchaka report at bugs.python.org
Thu Dec 9 13:25:58 EST 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

See issue660144 which made float values be rejected in most cases where an integer is expected rather of silently truncating them. It was at 2003. Guido mentioned that is an age-old problem, so perhaps you can find older discussions on the tracker or mailing lists.

It was a partial solution. It caught unexpected floats, but not other non-integer numbers. Later, the __index__ special method was introduced specially to distinguish objects which can be implicitly converted to integer from these which can be explicitly converted to integer. And finally we fixed that age-old problem.

If you have other questions, please ask them on mailing lists, forums or other resources.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36048>
_______________________________________


More information about the Python-bugs-list mailing list