Skip to content

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

Closed

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.

Activity

  1. added a commit that references this issue on Jan 4, 2019
    79f14b0
  2. added a commit that references this issue on Jan 4, 2019
    103f5f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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