Closed
Description
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
- gh-132987: Support __index__() for "k" and "K" formats in PyArg_Parse #132988
- gh-132987: Support __index__() for unsigned integers in Argument Clinic #133011
- gh-132987: Support __index__() in the socket module #133093
- gh-132987: Support __index__() in the select.kqueue_event constructor #133094
- gh-132987: Support __index__() in the posix module #133096
- gh-132987: Support __index__() in the stat module #133097
- gh-132987: Support __index__() in the ssl.SSLContext.options setter #133098
- gh-132987: Support __index__() in the lzma module #133099
- gh-132987: Support __index__() in hashlib.scrypt() #133100