You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
regression in 3.13.4 Random.getrandbits when an int like object is passed #135326
There is an (unintended?) api break. In python 3.13.3, getrandbits() accepts an "integer-like" object as in:
Python 3.13.3 (main, Apr 11 2025, 13:41:26) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import random ; r = random.Random()
>>> from numpy import int64
>>> r.getrandbits(int64(20))
582096
but in python 3.13.4, getrandbits() fails as in:
Python 3.13.4 (main, Jun 8 2025, 19:43:01) [GCC 14.2.1 20250405] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import random ; r = random.Random()
>>> from numpy import int64
>>> r.getrandbits(int64(20))
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
r.getrandbits(int64(20))
~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: an integer is required
This causes trouble for sagemath, where integers are by default a special type ZZ.
changed the title [-]regression in 3.13.4 `Random.getrandbits` when an `int` subclass is passed[/-][+]regression in 3.13.4 `Random.getrandbits` when an `int` like object is passed[/+]on Jun 10, 2025
#135332 restores support without rolling back all changes.
Note that SystemRandom.getrandbits() does not support __index__, and never did. On other hand, SystemRandom.randbytes() supports __index__, but Random.randbytes() does not. Some other methods may support __index__, but currently there are no tests for this.
Activity
[-]regression in 3.13.4 `Random.getrandbits` when an `int` subclass is passed[/-][+]regression in 3.13.4 `Random.getrandbits` when an `int` like object is passed[/+]pythongh-135326: Revert "[3.13] pythongh-133489: Remove size restrict…
gpshead commentedon Jun 10, 2025
I went for a revert of the change. Easiest. We can live without that old bug being fixed in 3.13. The fix works in 3.14+.
[3.13] pythongh-135326: Restore support of __index__ in random.getran…
serhiy-storchaka commentedon Jun 10, 2025
#135332 restores support without rolling back all changes.
Note that
SystemRandom.getrandbits()does not support__index__, and never did. On other hand,SystemRandom.randbytes()supports__index__, butRandom.randbytes()does not. Some other methods may support__index__, but currently there are no tests for this.[3.13] gh-135326: Restore support of __index__ in random.getrandbits() (
pythongh-135326: Test support of __index__ in random.getrandbits()
gh-135326: Test support of __index__ in random.getrandbits() (#135356)
pythongh-135326: Test support of __index__ in random.getrandbits() (p…
gpshead commentedon Jun 11, 2025
thanks! ❤
[3.14] gh-135326: Test support of __index__ in random.getrandbits() (G…
python3: fix a regression
python3: fix a regression
pythongh-135326: Test support of __index__ in random.getrandbits() (p…
python3: fix a regression
pythongh-135326: Test support of __index__ in random.getrandbits() (p…
pythongh-135326: Test support of __index__ in random.getrandbits() (p…
pythongh-135326: Test support of __index__ in random.getrandbits() (p…