Skip to content
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] Loading type from imported modules. #18158

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mypyc/irbuild/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,11 @@ def load_type(builder: IRBuilder, typ: TypeInfo, line: int) -> Value:
elif typ.fullname in builtin_names:
builtin_addr_type, src = builtin_names[typ.fullname]
class_obj = builder.add(LoadAddress(builtin_addr_type, src, line))
elif typ.module_name in builder.imports:
loaded_module = builder.load_module(typ.module_name)
class_obj = builder.builder.get_attr(
loaded_module, typ.name, object_rprimitive, line, borrow=False
)
else:
class_obj = builder.load_global_str(typ.name, line)

Expand Down
13 changes: 13 additions & 0 deletions mypyc/test-data/run-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ assert hasattr(c, 'x')
1000000000000000000000000000001
1000000000000000000000000000002

[case testTypedDictWithFields]
import collections
from typing_extensions import TypedDict
class C(TypedDict):
x: collections.deque
[file driver.py]
from native import C
from collections import deque

print(C.__annotations__["x"] is deque)
[out]
True

[case testClassWithDeletableAttributes]
from typing import Any, cast
from testutil import assertRaises
Expand Down
Loading