[docs] [issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie)

Mark Dickinson report at bugs.python.org
Mon Jun 3 02:46:54 EDT 2019


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

> Can we at least switch to PyLong_CheckExact?

+1

> I am not sure that converting to an exact int in low-level C API functions is the best option.

I am sure. :-)  The number of naturally-occurring cases where we're actually passing a subtype of `int` that's not exactly `int` should be tiny. So long as there's a PyLong_CheckExact fast path, I don't think there are really any performance concerns here.

And we definitely shouldn't let performance concerns dictate API; get the API right first, _then_ see what can be done about performance without changing the API. It's clear to me that `operator.index(obj)` _should_ give the exact same results as `obj.__index__()`.

I'll split my PR up into two pieces, one for turning the deprecated behaviour into TypeErrors, and a second one that just makes the PyLong_CheckExact change. (I likely won't have time before feature freeze, though. OTOH, the PyLong_CheckExact change could be considered a bugfix.)

----------

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


More information about the docs mailing list