-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
TYP: mypy believes enumerate
returns float64
instead of NDArray
#28245
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
I can reproduce this on the main branch, but only with mypy: import numpy as np
import numpy.typing as npt
a: npt.NDArray[np.float64]
reveal_type(iter(a)) Mypy 1.14.1:
Pyright 1.1.392:
This is caused by a bug in mypy (probably python/mypy#14070). To see why I think mypy is behaving incorrectly, you could take a look at the definition for Lines 2570 to 2577 in a1fa8e1
The only overload that could return a I don't see any reason why mypy would behave this way,.. So I also don't know how we could work around this. It's probably a good idea to raise this with mypy &mdhash; they have been very helpful recently in fixing numpy-related issues (see python/mypy#18343). |
Thanks for taking the time to look into this and suggesting a possible cause of the problem. I've raised the issue with mypy: python/mypy#18566. I'll go ahead and close this issue and continue monitoring the situation on the mypy side. |
Describe the issue:
In the code example
a
is[[1. 1.] [1. 1.]]
andai
is[1. 1.]
, a one-dimensional array. However, mypy flags the call tofoo(ai)
and complains thatai
is not anNDArray
. The snippet below illustrates the issue focusing onenumerate
, but I actually encountered the same behavior withzip
.I tested the same logic with numpy: 2.1.3 and mypy 1.14.1, and there were no errors.
Reproduce the code example:
Error message:
Python and NumPy Versions:
numpy: 2.2.2
Python: 3.12.8 (main, Jan 22 2025, 21:56:05) [GCC 11.4.0]
Type-checker version and settings:
mypy 1.14.1 (compiled: yes)
mypy myproblem.py
Additional typing packages.
No response
The text was updated successfully, but these errors were encountered: