Closed
Description
Bug report
Bug description:
via #133489 (comment) @tornaria reports:
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
.
CPython versions tested on:
3.13
Operating systems tested on:
No response
Linked PRs
- [3.13] gh-135326: Revert "[3.13] gh-133489: Remove size restrictions on getrandbits() and randbytes() (GH-133658) (GH-134965) #135327
- [3.13] gh-135326: Restore support of __index__ in random.getrandbits() #135332
- gh-135326: Test support of __index__ in random.getrandbits() #135356
- [3.14] gh-135326: Test support of __index__ in random.getrandbits() (GH-135356) #135373
Metadata
Metadata
Assignees
Projects
Status
Done