Skip to content

Conversation

@jorenham
Copy link
Member

... for the (most commonly used) 1-d cases, that is.

This also makes the return dtypes for the non-float64 cases a bit more user-friendly (floating and complexfloating can be annoying to work with).

@github-actions

This comment has been minimized.

@jorenham
Copy link
Member Author

The xarray primer error is the reassignment of 2d array to 1d array, which mypy doesn't support (unless you run mypy with --local-partial-types --allow-redefinition-new): https://github.com/pydata/xarray/blob/26ccc7f8f014f29c551fd566a04d6e9f878c0b0b/xarray/tests/test_plot.py#L562-L564

And for colour the story is the same: https://github.com/colour-science/colour/blob/6746a9c1dc9b9018e3a10ccaf3e63305342ee49d/colour/temperature/tests/test_ohno2013.py#L95-L98

@github-actions
Copy link

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: note: In member "test__infer_interval_breaks_logscale" of class "TestPlot":
+ xarray/tests/test_plot.py:564: 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/colorimetry/spectrum.py:559: error: Incompatible return value type (got "ndarray[tuple[Any, ...], dtype[generic[Any]]]", expected "ndarray[tuple[Any, ...], dtype[floating[_16Bit] | floating[_32Bit] | float64]]")  [return-value]
+ colour/colorimetry/spectrum.py:559: error: Incompatible return value type (got "ndarray[tuple[int], dtype[generic[Any]]]", expected "ndarray[tuple[Any, ...], dtype[floating[_16Bit] | floating[_32Bit] | float64]]")  [return-value]
+ colour/temperature/tests/test_ohno2013.py:98: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[float64]]", variable has type "ndarray[tuple[int], dtype[float64]]")  [assignment]
+ colour/plotting/tests/test_common.py:303: error: Redundant cast to "list[float]"  [redundant-cast]

@charris
Copy link
Member

charris commented Dec 28, 2025

I take it you see this as a mypy problem?

@jorenham
Copy link
Member Author

I take it you see this as a mypy problem?

Yup, and a solved one at that.

@charris charris merged commit 3735456 into numpy:main Dec 28, 2025
13 checks passed
@charris
Copy link
Member

charris commented Dec 28, 2025

Thanks Joren.

@jorenham jorenham deleted the typing/linspace-shape-typing branch December 28, 2025 20:12
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