Skip to content

regression in 3.13.4 Random.getrandbits when an int like object is passed #135326

Closed
@gpshead

Description

@gpshead

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

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixesrelease-blockertype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions