-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Wrong typing warning for map. (Argument X to "map" has incompatible type overloaded function) #6811
Comments
I can reproduce this on master. Mypy is also extremely slow to typecheck this fairly small file:
Maybe it hits some pathological case because there are so many nested functions with complex types? As for the originally reported bug, it also repros with this simpler code: def get_common_index(*names: str) -> int:
x = map(reversed, names)
return 0 Here is another repro that doesn't rely on the typeshed types of map and reversed: from typing import Iterator, Any, TypeVar, overload, List, Tuple, Callable, Iterable, Sequence
_T = TypeVar("_T")
_S = TypeVar("_S")
@overload
def reversed2(obj: Tuple[_T, ...]) -> Iterator[_T]:
pass
@overload
def reversed2(obj: Sequence[_T]) -> Iterator[_T]:
pass
def reversed2(obj: Any) -> Any:
raise Exception
def map2(func: Callable[[_T], _S], iter1: Iterable[_T]) -> Iterator[_S]:
raise Exception
def get_common_index(names: List[str]) -> None:
map2(reversed2, names) produces |
It may be just another manifestation of #1317: passing one generic function to another generic function doesn't work correctly. |
Also I am worried about the performance here, 200 seconds for few lines of not so deeply nested code is too much. |
I think you're right, the previous example in #3193 is very similar. Maybe we should keep this issue open to deal with the performance issue. |
Good idea! Should we add a label for performance issues? |
OK, I added the label and applied to a bunch of issues. |
The performance issues with this snippet of code seem to still be here on mypy 0.942, though I can't reproduce anything as severe as 200 seconds. The error message for the original example is now different (I think due to changes in typeshed): def get_common_index(*names: str) -> int:
x = map(reversed, names) # error: Argument 1 to "map" has incompatible type "Type[reversed[Any]]"; expected "Callable[[str], reversed[_T]]"
return 0 @JelleZijlstra's repro that avoids the typeshed stubs still reproduces exactly, however. |
It is **very** likely that this has been caused by a bug in mypy. See: python/mypy#6811
I write this function to check the rightmost common element of two list.
this is the code.
It works fine, and the input types are correct.
But mypy raise the following error message.
Is this an error of mypy?
The text was updated successfully, but these errors were encountered: