-
Notifications
You must be signed in to change notification settings - Fork 766
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
Incorrect type/operator error for numpy ArrayLike #1198
Comments
I think this is a duplicate of #1182, and will likely be fixed in the next release. |
Hm, maybe not. |
I'm inclined to believe that this is working as intended. Take this call for example: test_func(1234, [1, 2, 3]) This fails at runtime, but the definition of ArrayLike = Union[
_ScalarLike,
Sequence[_ScalarLike],
Sequence[Sequence[Any]], # TODO: Wait for support for recursive types
_SupportsArray,
] Two things being in this union doesn't imply that they are actually compatible. Under the hood, I believe numpy converts its array-like parameters as needed depending on the operation, but a function that tries to just do |
If you wanted to be able to handle numpy arrays, you'd probably want: from numpy import ndarray
def test_func(x: ndarray, y: ndarray) -> ndarray:
return x + y This does type check. Or, something like: import numpy as np
from numpy.typing import ArrayLike
def test_func(x: ArrayLike, y: ArrayLike) -> np.ndarray:
return np.array(x) + y |
PyLance doesn't handle
numpy
types appropriately and shows them as type errors when attempting to perform operations with them that do exist. Possibly related to numpy/numpy#16515 or #150.Environment data
pyenv
)Expected behaviour
Numpy arrays can be added, subtracted, multiplied, etc and shouldn't show up as an error.
Actual behaviour
Code Snippet / Additional information
The text was updated successfully, but these errors were encountered: