Skip to content

Conversation

@ilevkivskyi
Copy link
Member

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()).

Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ilevkivskyi
Copy link
Member Author

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
@ilevkivskyi ilevkivskyi deleted the fix-type-meta-proper branch February 23, 2019 01:33
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.

Inconsistency in metaclass/Type interaction Inheritance broken when testing isinstance? Binder doesn't work well with Type[...]

2 participants