Skip to content

Improve type inference for "Optional[T] or T" expression #1817

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

Closed
gvanrossum opened this issue Jul 7, 2016 · 1 comment · Fixed by #1828
Closed

Improve type inference for "Optional[T] or T" expression #1817

gvanrossum opened this issue Jul 7, 2016 · 1 comment · Fixed by #1828
Assignees

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Jul 7, 2016

Consider this:

def f(a: Optional[str]) -> str:
    return a or 'default'

This should type-check under --strict-optional, but currently the type of a or 'default' is inferred as Optional[str]. It should realize that if a is None the right branch is always taken.

@gvanrossum gvanrossum changed the title Improve type inference for Optional[x] Improve type inference for "Optional[T] or T" expression Jul 7, 2016
@gvanrossum gvanrossum self-assigned this Jul 7, 2016
@JukkaL
Copy link
Collaborator

JukkaL commented Jul 7, 2016

Dupe of #1733?

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