Skip to content

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

Closed
@JukkaL

Description

@JukkaL

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions