Skip to content
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

Fix interaction of isinstance() with Type[...] #6419

Merged
merged 6 commits into from Feb 23, 2019

Conversation

@ilevkivskyi
Copy link
Collaborator

commented Feb 17, 2019

Fixes #4616
Fixes #6416
Fixes #6386

Currently Type[C] is considered a subtype of metaclass of C, and I think this is right. The idea is to fix ProperSubtypeVisitor.visit_type_type() to match SubtypeVisitor.visit_type_type() (plus couple small updates to make the former used by isinstance() and issubclass()).

@ilevkivskyi ilevkivskyi requested review from msullivan and JukkaL Feb 17, 2019

@msullivan
Copy link
Collaborator

left a comment

This looks good! Check it on internal codebases before merging?

@msullivan
Copy link
Collaborator

left a comment

This seems reasonable. I wonder if there is a long-term way to clean up some of the complicated interactions involving Type, though

item = left.item
if isinstance(item, TypeVarType):
item = item.upper_bound
if isinstance(item, Instance):

This comment has been minimized.

Copy link
@msullivan

msullivan Feb 22, 2019

Collaborator

There is a "TODO: handle metaclasses?" comment above that I think can be removed now

@ilevkivskyi

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 23, 2019

I wonder if there is a long-term way to clean up some of the complicated interactions involving Type, though

I was thinking about this, but it looks like this part of the type system is inherently complex. (Especially if we want to keep it usable in practice.) Also there are still many holes in the type visitors, just few lines above is:

    def visit_overloaded(self, left: Overloaded) -> bool:
        # TODO: What's the right thing to do here?
        return False

The meet visitor (and related helpers) probably require the most attention.

@ilevkivskyi ilevkivskyi merged commit ed0dcad into python:master Feb 23, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@ilevkivskyi ilevkivskyi deleted the ilevkivskyi:fix-type-meta-proper branch Feb 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.