You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type revealed by mypy depends on whether the array is assigned to a variable or not. This may very well be a mypy bug.
Reproduce the code example:
importnumpy.typingasnptimportnumpyasnpfromtypingimportoverload@overloaddeff(x: npt.NDArray[np.int64]) ->npt.NDArray[np.int64]:
...
@overloaddeff(x: npt.NDArray[np.float64]) ->npt.NDArray[np.float64]:
...
deff(x):
returnxa=np.array([1, 2, 3], dtype=np.int64)
reveal_type(a)
reveal_type(f(a))
reveal_type(f(np.array([1, 2, 3], dtype=np.int64)))
b=np.array([1, 2, 3], dtype=np.float64)
reveal_type(b)
reveal_type(f(b))
# This final one returns int64 not float64reveal_type(f(np.array([1, 2, 3], dtype=np.float64)))
Error message:
blah.py:18: note: Revealed type is "numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[numpy._typing._64Bit]]]"
blah.py:19: note: Revealed type is "numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[numpy._typing._64Bit]]]"
blah.py:20: note: Revealed type is "numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[numpy._typing._64Bit]]]"
blah.py:23: note: Revealed type is "numpy.ndarray[Any, numpy.dtype[numpy.floating[numpy._typing._64Bit]]]"
blah.py:24: note: Revealed type is "numpy.ndarray[Any, numpy.dtype[numpy.floating[numpy._typing._64Bit]]]"
blah.py:25: note: Revealed type is "numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[numpy._typing._64Bit]]]"
The final 3 revealed types should be "numpy.ndarray[Any, numpy.dtype[numpy.floating[numpy._typing._64Bit]]]", but for some reason the final is "numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[numpy._typing._64Bit]]]" instead.
The text was updated successfully, but these errors were encountered:
Yeah, this definitely sounds like a mypy bug. I've got the suspicion that mypy chokes somewhere and ends up with a Any-based dtype, one that passes through the first overload by simply using that as a default.
Describe the issue:
The type revealed by mypy depends on whether the array is assigned to a variable or not. This may very well be a mypy bug.
Reproduce the code example:
Error message:
NumPy/Python version information:
1.23.4 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]
Context for the issue:
The final 3 revealed types should be "numpy.ndarray[Any, numpy.dtype[numpy.floating[numpy._typing._64Bit]]]", but for some reason the final is "numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[numpy._typing._64Bit]]]" instead.
The text was updated successfully, but these errors were encountered: