Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: Fix overlapping overloads issue in "2 in, 1 out" ufuncs #28168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

jorenham
Copy link
Member

Closes #28162


before:

import numpy as np
import numpy.typing as npt

a: npt.NDArray[np.float64] | np.float64
b: npt.NDArray[np.float64] | np.float64
out = np.logical_or(a, b)
reveal_type(out)  # npt.NDArray[Any]  <-- no scalar

after:

import numpy as np
import numpy.typing as npt

a: npt.NDArray[np.float64] | np.float64
b: npt.NDArray[np.float64] | np.float64
out = np.logical_or(a, b)
reveal_type(out)  # npt.NDArray[Any] | Any

The same fix has also been applied to .outer

@jorenham
Copy link
Member Author

It's a bug that has gone by unnoticed for 4 years, so I'm not sure whether this should be a backport candidate or not. What do you think @charris?

Copy link

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

pandas (https://github.com/pandas-dev/pandas)
- pandas/core/frame.py:11608: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[Any]]", variable has type "ndarray[tuple[int], dtype[Any]]")  [assignment]

@jorenham
Copy link
Member Author

@hauntsaninja maybe it's old news, but mypy primer seems to work πŸŽ‰

@charris
Copy link
Member

charris commented Jan 16, 2025

I'm not sure whether this should be a backport

We will be supporting 2.2.x for another 5-6 months and I would like to make the typing as good as we can. I think there is minimal risk in doing so.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Jan 16, 2025
@charris charris merged commit 865dcc1 into numpy:main Jan 16, 2025
70 checks passed
@charris
Copy link
Member

charris commented Jan 16, 2025

Thanks Joren.

@jorenham jorenham deleted the fix-28162 branch January 16, 2025 22:38
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 17, 2025
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.

TYP: Return type for logical_or too narrow
2 participants