Skip to content

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

@msullivan

Description

@msullivan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions