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
TYP: concatenate
typing produces unexpected errors
#20901
Comments
I think you may have stumbled upon a mypy bug related to the special casing of tuples. The first three cases succesfully pick the appropriate overload, but the last one somehow ends up at one that's meant for array-likes implementing import numpy as np
np.concatenate((np.array(1), np.array(1))) # No error
np.concatenate(([1], [1])) # No error
np.concatenate([[1], np.array(1)]) # No error
np.concatenate(([1], np.array(1))) # Argument 1 to "concatenate" has incompatible type |
Thanks @BvB93 . Is there a workaround, other than copying to a new array? I tried using list instead of tuple for input but it didn't have it. It seems to me having the array first is hitting the issue (this I can't change). np.concatenate([np.array(1), [1]]) |
I'm not sure if I'm following, does the example you provided in #20901 (comment) work or does it not? If it does, then I'd recommend replacing the outermost tuple with a list as a stopgap measure. |
No, two errors. np.concatenate([[1], np.array(1)]) # Argument 1 to "concatenate" has incompatible type "List[object]"; expected "Union[_SupportsArray[dtype[<nothing>]], Sequence[_SupportsArray[dtype[<nothing>]]], Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]"
np.concatenate(([1], np.array(1))) # Argument 1 to "concatenate" has incompatible type "Tuple[List[int], ndarray[Any, dtype[Any]]]"; expected "Union[_SupportsArray[dtype[<nothing>]], Sequence[_SupportsArray[dtype[<nothing>]]], Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]" FWIW
|
Weird, the error for the first one seems to disappear when using the numpy I do think I've found the culprit though.
|
If it's a mypy bug, has it been raised with them? I linked them to this issue here python/mypy#12144 but they've pushed back that it's a numpy bug and I don't have the context to know what the explicit bug is in mypy. |
Describe the issue:
Running mypy against 1.22.1 on correct code produces an error.
I think
_SupportsArray
seems to be wrong, and it should be_ArrayLike
Reproduce the code example:
The text was updated successfully, but these errors were encountered: