Skip to content

TYP: Improved np.array shape-typing - #32081

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/np.array/better-shape-typing
Jul 23, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/np.array/better-shape-typing

Conversation

@jorenham

Copy link
Copy Markdown
Member

For some reason I thought I had already done this, but apparently not 🤷.


No AI.

@jorenham jorenham added this to the 2.6.0 Release milestone Jul 23, 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/internal_test_util/test_harnesses.py:1226: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "list[list[int]]")  [assignment]
+ jax/_src/internal_test_util/test_harnesses.py:1226: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[signedinteger[_32Bit | _64Bit]]]", variable has type "list[list[int]]")  [assignment]
- jax/_src/internal_test_util/test_harnesses.py:1267: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "list[list[int]]")  [assignment]
+ jax/_src/internal_test_util/test_harnesses.py:1267: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[signedinteger[_32Bit | _64Bit]]]", variable has type "list[list[int]]")  [assignment]

colour (https://github.com/colour-science/colour)
- colour/plotting/models.py:1457: error: Incompatible types in assignment (expression has type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]", variable has type "ndarray[tuple[Any, ...], dtype[Any]]")  [assignment]
+ colour/plotting/models.py:1457: error: Incompatible types in assignment (expression has type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]", variable has type "ndarray[Any, Any]")  [assignment]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/util.py:1272: error: Returning Any from function declared to return "dtype[Any]"  [no-any-return]

scipy (https://github.com/scipy/scipy)
- scipy/stats/_morestats.py:2280: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "list[list[float]]")  [assignment]
+ scipy/stats/_morestats.py:2280: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[float64]]", variable has type "list[list[float]]")  [assignment]
- scipy/stats/tests/test_distributions.py:2008: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[Any]]", variable has type "list[list[float]]")  [assignment]
+ scipy/stats/tests/test_distributions.py:2008: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[float64]]", variable has type "list[list[float]]")  [assignment]

@charris
charris merged commit edf400b into numpy:main Jul 23, 2026
15 checks passed
@charris

charris commented Jul 23, 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