Skip to content

Keep Any when restricting Union in isinstance - #2446

Merged
JukkaL merged 2 commits into
python:masterfrom
ilevkivskyi:keep-union-any
Nov 15, 2016
Merged

Keep Any when restricting Union in isinstance#2446
JukkaL merged 2 commits into
python:masterfrom
ilevkivskyi:keep-union-any

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Fixes#1720

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

deffunc(v: Union[int, Any]) ->None:
ifisinstance(v, int):
reveal_type(s) # This is correctly intelse:
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
Copy Markdown
Member

Probably best for @ddfisher or @JukkaL to review.

@JukkaL

Copy link
Copy Markdown
Collaborator

Looks good -- thanks!

@JukkaL
JukkaL merged commit a488641 into python:masterNov 15, 2016
Sign up for freeto 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

@ilevkivskyi@gvanrossum@JukkaL