Closed
Description
Describe the issue:
In the code example a
is [[1. 1.] [1. 1.]]
and ai
is [1. 1.]
, a one-dimensional array. However, mypy flags the call to foo(ai)
and complains that ai
is not an NDArray
. The snippet below illustrates the issue focusing on enumerate
, but I actually encountered the same behavior with zip
.
I tested the same logic with numpy: 2.1.3 and mypy 1.14.1, and there were no errors.
Reproduce the code example:
import numpy as np
import numpy.typing as npt
def foo(x: npt.NDArray[np.float64]) -> None:
print(x)
a = np.ones([2, 2])
for _, ai in enumerate(a):
foo(ai)
Error message:
error: Argument 1 to "foo" has incompatible type "float64"; expected "ndarray[tuple[int, ...], dtype[float64]]" [arg-type]
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