Skip to content

TYP: fix np.random.{get,set}_bit_generator implicit re-exports - #32257

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/random/fix-implicit-reexports
Aug 12, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/random/fix-implicit-reexports

Conversation

@jorenham

@jorenham jorenham commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

At runtime, np.random re-exports get_bit_generator, yet it's not in np.random.__all__:

>>> import numpy as np
>>> np.random.get_bit_generator()
<numpy.random._mt19937.MT19937 object at 0x12ab85a0>
>>> "get_bit_generator" in np.random.__all__
False

The way to express this in the stubs is by using a redundant symbol alias (viz. import x as x), as specified in the Python typing spec: https://typing.python.org/en/latest/spec/distributing.html#import-conventions
Without this redundant alias (the current sitiation) accessing np.random.get_bit_generator will cause checkers to report an error:

image

No AI.

@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

optuna (https://github.com/optuna/optuna)
  ./optuna/study/_multi_objective.py:182: error: INTERNAL ERROR -- Please try using mypy master on GitHub:

@charris
charris merged commit b61d8f9 into numpy:main Aug 12, 2026
15 checks passed
@charris

charris commented Aug 12, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

@jorenham
jorenham deleted the typing/random/fix-implicit-reexports branch August 12, 2026 16:13
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Aug 14, 2026
charris added a commit that referenced this pull request Aug 14, 2026
TYP: fix ``np.random.{get,set}_bit_generator`` implicit re-exports (#32257)
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