Description
Yet one strange thing about member setters with unsigned integer type is that they support different ranges for int
and int-like objects (objects with the __index__()
method).
For Py_T_ULONG the range for int
is LONG_MIN
-ULONG_MAX
, but for indexes it is smaller: LONG_MIN
-LONG_MAX
.
The same is for Py_T_UINT, except that the maximal hard limit for index LONG_MAX
can be larger than the maximal safe limit UINT_MAX
, depending on platform, so on some platforms it may be lesser issue.
Py_T_ULLONG is even more limited. The range for int
is 0-ULLONG_MAX
(negatives not allowed!), and the range for indexes is LONG_MIN
-LONG_MAX
, which includes negatives, bat has much lesser upper limit. It is a remnant of dark old times, when Python had two not yet completely compatible integer types.
Py_T_PYSSIZET does not support __index__()
at all. It is because PyLong_AsSsize_t()
does not support them.
Linked PRs
- gh-115011: Improve support of __index__() in setters of members with unsigned integer type #115029
- [3.12] gh-115011: Improve support of __index__() in setters of members with unsigned integer type (GH-115029) #115294
- [3.11] gh-115011: Improve support of __index__() in setters of members with unsigned integer type (GH-115029) #115295