Skip to content

TYP: broadcast_shapes shape-typing - #32638

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/broadcast_shapes/shape-typing
Sep 15, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/broadcast_shapes/shape-typing

Conversation

@jorenham

Copy link
Copy Markdown
Member

np.broadcast_shapes used to always return tuple[Any, ...] (the unknown / "gradual" shape-type). This overloads it for the 0, 1, and 2 argument cases and input dimensions of up to 3d.


Pair programmed with AI.

@jorenham jorenham added this to the 2.6.0 Release milestone Sep 15, 2026
@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:

jax (https://github.com/google/jax)
- jax/_src/state/indexing.py:254: error: Argument 2 to "broadcast_to" has incompatible type "tuple[int | Array, ...] | tuple[Any, ...]"; expected "tuple[int, ...]"  [arg-type]

@charris
charris merged commit a140638 into numpy:main Sep 15, 2026
16 checks passed
@charris

charris commented Sep 15, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

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