Skip to content

Type inference of list comprehension and Optional[t] #1734

Closed
@JukkaL

Description

@JukkaL

The type of b is incorrectly List[Union[None, int]] instead of List[int] when using --strict-optional:

from typing import Optional, List
a = [] # type: List[Optional[int]]
b = [x for x in a if x]
reveal_type(b)

Generators and other comprehensions are related (not checked them).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions