The __index__() special method was introduced to make other integer-like types which are not int subclasses to be accepted as integer arguments.
It is supported by all PyArg_Parse format units for integers, except k (long sized bitfield) and K (long long sized bitfield). Argument Clinic has the same behavior for unsigned_long(bitwise=True) and unsigned_long_long(bitwise=True). It supports also non-bitwise unsigned integer converters, all of them do not support __index__().
Note that making PyLong_AsUnsignedLong() and PyLong_AsUnsignedLongLong() to support __index__() is potentially unsafe. But the higher level code that uses them, can be changed.
Linked PRs
The
__index__()special method was introduced to make other integer-like types which are notintsubclasses to be accepted as integer arguments.It is supported by all
PyArg_Parseformat units for integers, exceptk(long sized bitfield) andK(long long sized bitfield). Argument Clinic has the same behavior forunsigned_long(bitwise=True)andunsigned_long_long(bitwise=True). It supports also non-bitwise unsigned integer converters, all of them do not support__index__().Note that making
PyLong_AsUnsignedLong()andPyLong_AsUnsignedLongLong()to support__index__()is potentially unsafe. But the higher level code that uses them, can be changed.Linked PRs