-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix interaction of isinstance() with Type[...] #6419
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
Conversation
msullivan
left a comment
There was a problem hiding this 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?
msullivan
left a comment
There was a problem hiding this 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): |
There was a problem hiding this comment.
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
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 FalseThe meet visitor (and related helpers) probably require the most attention. |
Fixes #4616
Fixes #6416
Fixes #6386
Currently
Type[C]is considered a subtype of metaclass ofC, and I think this is right. The idea is to fixProperSubtypeVisitor.visit_type_type()to matchSubtypeVisitor.visit_type_type()(plus couple small updates to make the former used byisinstance()andissubclass()).