Skip to content

TYP: hstack and vstack shape-typing - #32238

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/-stack/shape-typing
Aug 10, 2026
Merged

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

Conversation

@jorenham

@jorenham jorenham commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

As part of https://gist.github.com/jorenham/36c78602a7ca866ddb2a917de48ccdd0, this improves shape-typing for np.hstack and np.vstack.


This one was actually mostly written by AI! It came out pretty much exactly as I would have written it, so that's kinda awesome (and a bit scary).

@jorenham jorenham added this to the 2.6.0 Release milestone Aug 10, 2026
@github-actions

This comment has been minimized.

@jorenham

jorenham commented Aug 10, 2026 •

Copy link
Copy Markdown
Member Author

RE: the mypy_primer diff:

@jorenham

This comment was marked as resolved.

@jorenham
jorenham marked this pull request as draft August 10, 2026 12:34
@jorenham
jorenham force-pushed the typing/-stack/shape-typing branch from 29f5263 to c42c4f3 Compare August 10, 2026 12:48
@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:

xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_plot.py:566: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[float64]]", variable has type "ndarray[tuple[int], dtype[float64]]")  [assignment]

colour (https://github.com/colour-science/colour)
- colour/plotting/section.py:247: error: List item 0 has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | str | None"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [list-item]
- colour/plotting/section.py:247: error: List item 1 has incompatible type "float"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [list-item]
- colour/plotting/diagrams.py:599: error: List item 0 has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | str | None"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [list-item]
- colour/plotting/diagrams.py:599: error: List item 1 has incompatible type "float"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [list-item]
- colour/plotting/diagrams.py:604: error: List item 0 has incompatible type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | str | None"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [list-item]
- colour/plotting/diagrams.py:604: error: List item 1 has incompatible type "float"; expected "_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]]"  [list-item]

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

@jorenham
jorenham marked this pull request as ready for review August 10, 2026 14:17
@charris

charris commented Aug 10, 2026

Copy link
Copy Markdown
Member

Should we wait on mypy?

@jorenham

Copy link
Copy Markdown
Member Author

Should we wait on mypy?

Nah, it might be weeks or even months until the next mypy release, and the internal error only causes mypy_primer to not run on optuna, so it should be fine to ignore.

@charris
charris merged commit feed9a8 into numpy:main Aug 10, 2026
14 checks passed
@charris

charris commented Aug 10, 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