-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix issubclass()
to narrow down types of type variables
#7930
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
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.
Thanks for PR! Here I have few comments.
Thanks for the detailed review! I patched it up in df62cbc
|
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.
Thanks for updates! Here are some more comments.
@@ -3726,32 +3726,7 @@ def find_isinstance_check(self, node: Expression | |||
elif refers_to_fullname(node.callee, 'builtins.issubclass'): | |||
if len(node.args) != 2: # the error will be reported elsewhere | |||
return {}, {} | |||
expr = node.args[0] | |||
if literal(expr) == LITERAL_TYPE: |
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.
I would keep the above two lines in this function. To make the refactoring more 1-to-1.
@@ -4194,6 +4169,40 @@ def push_type_map(self, type_map: 'TypeMap') -> None: | |||
for expr, type in type_map.items(): | |||
self.binder.put(expr, type) | |||
|
|||
def infer_issubclass_maps(self, node: CallExpr, | |||
type_map: Dict[Expression, Type] | |||
) -> Tuple[TypeMap, TypeMap]: |
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.
Please add a short docstring for the new function.
return other.field | ||
return 0 | ||
|
||
[builtins fixtures/isinstancelist.pyi] |
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.
OK, now the two classes don't look the same, but you didn't do what I asked, I wanted type variables with different upper bounds, like Type[SomeClass]
, not just type
.
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.
Some more comments here. Also please don't hurry, it is not a competition.
You are right and I shouldn't be in such a hurry. I had some misunderstanding about this issue from the very beginning and that mistake continues in my testcase. I apologize for that and am trying my best to fill my knowledge gap on type systems(mainly by reading TAPL) Now I look it again and realize |
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.
Looks good now, thanks!
Thanks for the guidance! Again, quite an education on both software engineering and type system aspects and that means a lot to me. |
resolves #7920
Currently, no testcases break so I did not look into
meet.py
for further investigation