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

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

Closed
JukkaL opened this issue Jun 22, 2016 · 1 comment
Closed

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

JukkaL opened this issue Jun 22, 2016 · 1 comment

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 22, 2016

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).

@ddfisher
Copy link
Collaborator

Rather than being strict optional specific, this is a general problem with Unions:

from typing import Optional, List, Union
a = [] # type: List[Union[int, str]]
b = [x for x in a if isinstance(x, int)]
reveal_type(b)  # E: Revealed type is 'builtins.list[Union[builtins.int, builtins.str]]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants