-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
TYP: ndarray.item
never typechecks
#27977
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
Comments
ndarray.item
never matchesndarray.item
never typechecks
This is invalid: the 2nd type parameter of import numpy as np
def f(x: np.ndarray[tuple[int], np.dtype[np.double]]) -> float:
return x.item()
def g(x: np.ndarray[tuple[int], np.dtype[np.str_]]) -> str:
return x.item() which is accepted by both mypy and pyright Oh and quick tip, |
Awesome thanks! I guess that I just tried to replace |
Describe the issue:
In version 2.2.0, I have been completely unable to type the return value of a call to
ndarray.item()
which does not fail type checking. I have tried both MyPy and Pyright.Am I doing something wrong here? Or is it an issue with the type checker(s)? It seems they don't even see all the overloads:
numpy/numpy/__init__.pyi
Lines 2111 to 2122 in a2012ad
Reproduce the code example:
Error message:
Python and NumPy Versions:
2.2.0
8000 3.11.10 (main, Sep 7 2024, 01:03:31) [GCC 11.4.0]
Type-checker version and settings:
pyright 1.1.390 with default settings
Additional typing packages.
No response
The text was updated successfully, but these errors were encountered: