Skip to content

Else block of isinstance check with promotable types has <nothing> for type #6141

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
msullivan opened this issue Jan 4, 2019 · 0 comments · Fixed by #6142
Closed

Else block of isinstance check with promotable types has <nothing> for type #6141

msullivan opened this issue Jan 4, 2019 · 0 comments · Fixed by #6142

Comments

@msullivan
Copy link
Collaborator

This test case

from typing import Union
def asdf(val: Union[int, float]):
    if isinstance(val, float):
        reveal_type(val)
    else:
        reveal_type(val)

produces:

/home/msullivan/lol2.py:4: error: Revealed type is 'builtins.float'
/home/msullivan/lol2.py:6: error: Revealed type is '<nothing>'

But the type in the else branch ought to be int.

Prior to #6114, it produced

/home/msullivan/lol2.py:4: error: Revealed type is 'Union[builtins.int, builtins.float]'

which is of course also wrong.
The prior version produced false positives in the then branch and false negatives in the else branch, while the new version produces false positives in the else branch and works correctly in the then branch.

msullivan added a commit that referenced this issue Jan 4, 2019
This fixes a bug left behind by #6114, where too much would get
subtracted out of a union type after an isinstance.

Fixes #6141.
msullivan added a commit that referenced this issue Jan 4, 2019
This fixes a bug left behind by #6114, where too much would get
subtracted out of a union type after an isinstance.

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

Successfully merging a pull request may close this issue.

1 participant