c.f. PyLong_AsUInt32/64():
If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.
In fact, there is no difference for signed/unsigned:
|
def test_long_asint32(self): |
|
# Test PyLong_AsInt32() and PyLong_FromInt32() |
|
to_int32 = _testlimitedcapi.pylong_asint32 |
|
from _testcapi import INT32_MIN, INT32_MAX |
|
self.check_long_asint(to_int32, INT32_MIN, INT32_MAX) |
|
def test_long_asuint32(self): |
|
# Test PyLong_AsUInt32() and PyLong_FromUInt32() |
|
as_uint32 = _testlimitedcapi.pylong_asuint32 |
|
from _testcapi import UINT32_MAX |
|
self.check_long_asint(as_uint32, 0, UINT32_MAX, |
|
negative_value_error=ValueError) |
where check_long_asint() tests
__index__() dunder per default:
|
def check_long_asint(self, func, min_val, max_val, *, |
|
use_index=True, |
|
mask=False, |
|
negative_value_error=OverflowError): |
So, same note should be added for PyLong_AsInt32/64()
Linked PRs
c.f. PyLong_AsUInt32/64():
In fact, there is no difference for signed/unsigned:
cpython/Lib/test/test_capi/test_long.py
Lines 691 to 695 in 3ec3d05
cpython/Lib/test/test_capi/test_long.py
Lines 703 to 708 in 3ec3d05
where check_long_asint() tests
__index__()dunder per default:cpython/Lib/test/test_capi/test_long.py
Lines 166 to 169 in 3ec3d05
So, same note should be added for PyLong_AsInt32/64()
Linked PRs