Skip to content

Keep Any when restricting Union in isinstance #2446

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

Merged
merged 2 commits into from
Nov 15, 2016

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