Skip to content

Commit 8a090d9

Browse files
committed
[mypyc] Loading type from imported modules.
1 parent 35048bf commit 8a090d9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mypyc/irbuild/function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,11 @@ def load_type(builder: IRBuilder, typ: TypeInfo, line: int) -> Value:
806806
elif typ.fullname in builtin_names:
807807
builtin_addr_type, src = builtin_names[typ.fullname]
808808
class_obj = builder.add(LoadAddress(builtin_addr_type, src, line))
809+
elif typ.module_name in builder.imports:
810+
loaded_module = builder.load_module(typ.module_name)
811+
class_obj = builder.builder.get_attr(
812+
loaded_module, typ.name, object_rprimitive, line, borrow=False
813+
)
809814
else:
810815
class_obj = builder.load_global_str(typ.name, line)
811816

mypyc/test-data/run-classes.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ assert hasattr(c, 'x')
7676
1000000000000000000000000000001
7777
1000000000000000000000000000002
7878

79+
[case testTypedDictWithFields]
80+
import collections
81+
from typing_extensions import TypedDict
82+
class C(TypedDict):
83+
x: collections.deque
84+
[file driver.py]
85+
from native import C
86+
from collections import deque
87+
88+
print(C.__annotations__["x"] is deque)
89+
[out]
90+
True
91+
7992
[case testClassWithDeletableAttributes]
8093
from typing import Any, cast
8194
from testutil import assertRaises

0 commit comments

Comments
 (0)