[issue40792] Make PyNumber_Index() always returning an exact int instance

Mark Dickinson report at bugs.python.org
Wed May 27 08:41:25 EDT 2020


Mark Dickinson <dickinsm at gmail.com> added the comment:

The behaviour change for range sounds reasonable to me.

Just to make sure I understand the impact of the change:

- For Python < 3.10, we sometimes convert the range inputs to Python ints, and sometimes don't. For example, a start value of `np.int64(5)` would be converted, but a value of `True` would not be.

- With this change, we'd always convert a non-int to an int, so both `np.int64(1)` and `True` would be converted to a `1` of exact type int.

IMO this is fine; the new behaviour seems more consistent than the old.

>>> import numpy as np
>>> start = np.int64(2)
>>> range(start, 5).start is start
False
>>> start = True
>>> range(start, 5).start is start
True

----------

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


More information about the Python-bugs-list mailing list