Skip to content
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

Invalid type for map(None, ...) when strict optional disabled (Python 2) #5251

Closed
JukkaL opened this issue Jun 20, 2018 · 1 comment
Closed
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high topic-overloads

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 20, 2018

Invalid type is inferred for this fragment when using -2 --no-strict-optional:

reveal_type(map(None, [1]))  # List[<nothing>]

The inferred type used to be Any in v0.610, so this is a regression. List[int] would be the most precise type.

Here is a more self-contained example that repros the issue (also in Python 3 mode, but strict optional must be disabled):

from typing import TypeVar, overload, Callable, Iterable, List

T = TypeVar('T')
S = TypeVar('S')

@overload
def f(c: Callable[[T], S], it: Iterable[T]) -> List[S]: ...
@overload
def f(c: None, it: Iterable[T]) -> List[T]: ...
def f(c, it): ...

reveal_type(f(None, [1]))  # List[<nothing>]

Moving the None overload to be the first item works around the issue, but I'm not sure yet if that will cause other trouble. If not, changing the builtins stubs is a potential workaround.

@JukkaL JukkaL added bug mypy got something wrong priority-0-high false-positive mypy gave an error on correct code topic-overloads labels Jun 20, 2018
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jun 20, 2018

Closing as duplicate of #5246.

@JukkaL JukkaL closed this as completed Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high topic-overloads
Projects
None yet
Development

No branches or pull requests

1 participant