Skip to content

Conversation

@ilevkivskyi
Copy link
Member

Fixes #1720

Currently, mypy incorrectly determines restrictions of unions containing Any after isinstance(), for example:

def func(v: Union[int, Any]) -> None:
    if isinstance(v, int):
        reveal_type(s) # This is correctly int
    else:
        reveal_type(s) # But this is incorrectly Union[<ERROR>, void], should be Any

This PR fixes this by not considering Any a subtype-of-every-type when restricting the union.

(Note that this PR is not a replacement for #2197 but a complement to it.)

@gvanrossum
Copy link
Member

Probably best for @ddfisher or @JukkaL to review.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 15, 2016

Looks good -- thanks!

@JukkaL JukkaL merged commit a488641 into python:master Nov 15, 2016
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 this pull request may close these issues.

type of Union containing Any is incorrectly inferred after an isinstance check

3 participants