Skip to content

Infer NumPy Generator.integers result shapes - #5652

Closed
AlessandroRuggiero wants to merge 1 commit into
pyrefly-org:mainfrom
AlessandroRuggiero:numpy-generator-integers
Closed

AlessandroRuggiero wants to merge 1 commit into
pyrefly-org:mainfrom
AlessandroRuggiero:numpy-generator-integers

Conversation

@AlessandroRuggiero

Copy link
Copy Markdown
Contributor

Same pattern as #5619: rng.integers now returns size's shape, or without size the broadcast shape of array low/high. The dtype is kept (int64 by default, or e.g. np.int32 / np.bool_), using a TypeVar default so one set of overloads covers both.

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Added tests to tensor-shapes/pyrefly-numpy-stubs/test/test_random.py covering scalar results, int, tuple, list and symbolic size, explicit dtypes, array bounds with and without size, and mismatched bounds.

Ran:

  • python3 tensor-shapes/pyrefly-numpy-stubs/run_pyrefly.py
  • "$TENSOR_SHAPES_VENV/bin/python" tensor-shapes/pyrefly-numpy-stubs/run_runtime_tests.py
  • ./test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension (formatting and lint)

@stroxler stroxler self-assigned this Nov 16, 2026

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind rebasing?

After the rename to pyrefly-org/pyrefly on Friday, our auto-import jobs paused; they seem to be working again so a rebase should get imported and I should be able to review/merge quicker.

AI review also flagged that some of these overloads may benefit from our IntTupleOrList[Shape] which can allow us to bind shapes from list literals (an actual list inevitably results in a gradual shape, that's harder to change).

@meta-cla meta-cla Bot added the cla signed label Nov 17, 2026
@github-actions

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Optional recommendations:

  • If this PR addresses an open issue, please link the issue in the PR description and claim it.
  • This PR is on the larger side. If parts of it could be merged on their own, consider splitting it into separate PRs for faster review. If you've already split it as far as is practical, no action is needed.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

@AlessandroRuggiero

Copy link
Copy Markdown
Contributor Author

@stroxler done

@meta-codesync

meta-codesync Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D132604672. (Because this pull request was imported automatically, there will not be any future comments.)

@meta-codesync

meta-codesync Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 90f0548.

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