Skip to content

TYP: fix random.RandomState.get_state conflicting overloads - #31881

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/random.RandomState.get_state
Jul 6, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/random.RandomState.get_state

Conversation

@jorenham

@jorenham jorenham commented Jul 6, 2026

Copy link
Copy Markdown
Member

Calling random.RandomState.get_state() (i.e. without passing legacy) incorrectly resulted in a dict[str, Any] output type because the first overload incorrectly has a legacy: Literal[False] = False default set. At runtime, it defaults to True.

According to Claude Fable 5 backporting this is a good idea because "state pickling is a common use of this API". I never use this API myself, so i'm not sure if that's true. So if you think it isn't, then just remove the backport-canditate label.


Fully written by me (a human, I think); bug found by Claude Fable 5 (high) (here's the full audit for those interested).

@jorenham
jorenham force-pushed the typing/random.RandomState.get_state branch from bcd8fde to 2306307 Compare July 6, 2026 18:10
@charris
charris merged commit 38ea8c4 into numpy:main Jul 6, 2026
13 checks passed
@charris

charris commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

@jorenham
jorenham deleted the typing/random.RandomState.get_state branch July 6, 2026 21:28
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 6, 2026
MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants