Repository navigation
Support __index__() for unsigned integer converters in PyArg_Parse and Argument Clinic #132987
Copy link
Copy link
Closed
Closed
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-argument-clinictype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Apr 26, 2025 - added 12 commits that reference this issue
on Apr 26, 2025 The following PRs change the code which do not use PyArg_Parse or Argument Clinic, but directly call
PyLong_AsUnsignedLong(),PyLong_AsUnsignedLongLong()orPyLong_AsSize_t(). In many case, the simplest way is to usePyLong_AsNativeBytes()or converters like_PyLong_UnsignedLongLong_Converter(), but the side effect is that ValueError is now raised instead of OverflowError for negative values. See also #74020.- added 7 commits that reference this issue
on Apr 29, 2025 Some code left in the
ctypesmodule, but I left it for later. This is a large issue, and not in all cases we may automatically use__index__. For example,int.__add__does not use__index__, they look similar.
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-argument-clinictype-featureA feature request or enhancementA feature request or enhancement
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