TYP: hstack and vstack shape-typing - #32238
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
Member
Author
|
RE: the mypy_primer diff:
|
This comment was marked as resolved.
This comment was marked as resolved.
jorenham
marked this pull request as draft
August 10, 2026 12:34
jorenham
force-pushed
the
typing/-stack/shape-typing
branch
from
August 10, 2026 12:48
29f5263 to
c42c4f3
Compare
|
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
marked this pull request as ready for review
August 10, 2026 14:17
Member
|
Should we wait on mypy? |
Member
Author
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. |
Member
|
Thanks Joren. |
This was referenced Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As part of https://gist.github.com/jorenham/36c78602a7ca866ddb2a917de48ccdd0, this improves shape-typing for
np.hstackandnp.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).