-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[mypyc] Using UnboundedType to access class object of a type annotation. #18874
base: master
Are you sure you want to change the base?
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 the PR! Not a full review yet, but left a few comments.
@@ -78,17 +78,22 @@ assert hasattr(c, 'x') | |||
|
|||
[case testTypedDictWithFields] | |||
import collections | |||
import json |
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.
What if as
is used in the import, such as import json as _json
? There could even be a case like this:
import a as b
import b as a
...
# b.C in an annotation refers to fullname a.C!
Similarly, what if we have from pkg import submod
and then submod.C
is used in an annotation?
It's okay to not support all possible cases yet -- we can create follow-up issues -- but it would be nice if we can avoid having references to incorrect types.
@@ -802,15 +802,41 @@ def get_func_target(builder: IRBuilder, fdef: FuncDef) -> AssignmentTarget: | |||
return builder.add_local_reg(fdef, object_rprimitive) | |||
|
|||
|
|||
def load_type(builder: IRBuilder, typ: TypeInfo, line: int) -> Value: | |||
def load_type(builder: IRBuilder, typ: TypeInfo, unbounded_type: Type | None, line: int) -> Value: | |||
# typ.fullname contains the module where the class object was defined. However, it is possible that the class |
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.
Style nit: some of the comments seem to be longer than 99 characters, which is our line length limit. Can you wrap any long lines?
Fixes mypyc/mypyc#1087.
This fix handles cases where type annotation is nested inside an imported module (like an inner class) or imported from a different module.