[mypyc] Using UnboundedType to access class object of a type annotation.#18874
[mypyc] Using UnboundedType to access class object of a type annotation.#18874JukkaL merged 3 commits intopython:masterfrom
Conversation
JukkaL
left a comment
There was a problem hiding this comment.
Thanks for the PR! Not a full review yet, but left a few comments.
|
|
||
| [case testTypedDictWithFields] | ||
| import collections | ||
| import json |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Both those cases are not supported. Opened mypyc/mypyc#1099 and referenced in a comment.
I will fix both after this PR is merged.
mypyc/irbuild/function.py
Outdated
|
|
||
| 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.
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?
JukkaL
left a comment
There was a problem hiding this comment.
This is reasonable as a first step towards solving the more general issue.
This is a follow up to #18874 which broke certain imports of type annotations. Fixes mypyc/mypyc#1099 Fixes mypyc/mypyc#1167 Fixes #20365 Closes mypyc/mypyc#1100
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.