bpo-20092. Use index in constructors of int, float and complex. by serhiy-storchaka · Pull Request #13108 · python/cpython (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: code looks good, and I agree that this is a desirable change.

The one fly in the ointment is that index can return something that's not an exact int, which means that there's now another code-path by which int can return something that's not of exact type int.

>>> class A:
...     def __index__(self): return True
... 
>>> int(A())
<stdin>:1: DeprecationWarning: __index__ returned non-int (type bool).  The ability to return an instance of a strict subclass of int is deprecated, and may be removed in a future version of Python.
1

I'd love to finally turn that DeprecationWarning into an error, but fear we've run out of time for that for 3.8, and we may want to wait for 3.9 anyway to make sure that everyone's had a chance to react to that warning. (Do you remember which version it got introduced in?)