Skip to content

Commit b23d9af

Browse files
committed
Fixing test failures.
1 parent 03b53cb commit b23d9af

File tree

3 files changed

+33
-61
lines changed

3 files changed

+33
-61
lines changed

mypyc/irbuild/function.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,11 @@ def load_type(builder: IRBuilder, typ: TypeInfo, unbounded_type: Type | None, li
823823
builtin_addr_type, src = builtin_names[typ.fullname]
824824
class_obj = builder.add(LoadAddress(builtin_addr_type, src, line))
825825
# This elif-condition finds the longest import that matches the load_attr_path.
826-
elif module_name := max((i for i in builder.imports if load_attr_path.startswith(i)), key=len):
826+
elif module_name := max(
827+
(i for i in builder.imports if load_attr_path == i or load_attr_path.startswith(f"{i}.")),
828+
default="",
829+
key=len,
830+
):
827831
# Load the imported module.
828832
loaded_module = builder.load_module(module_name)
829833
# Recursively load attributes of the imported module. These may be submodules, classes or any other object.

mypyc/test-data/commandline.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,31 @@ print("imported foo")
261261
importing...
262262
imported foo
263263
done
264+
265+
[case testImportFromInitPy]
266+
# cmd: foo.py
267+
import foo
268+
269+
[file pkg2/__init__.py]
270+
271+
[file pkg2/mod2.py]
272+
class A:
273+
class B:
274+
pass
275+
276+
[file pkg1/__init__.py]
277+
from pkg2.mod2 import A
278+
279+
[file foo.py]
280+
import pkg1
281+
from typing import TypedDict
282+
283+
class Eggs(TypedDict):
284+
obj1: pkg1.A.B
285+
286+
print(type(Eggs(obj1=pkg1.A.B())["obj1"]).__name__)
287+
print(type(Eggs(obj1=pkg1.A.B())["obj1"]).__module__)
288+
289+
[out]
290+
B
291+
pkg2.mod2

mypyc/test/test_function.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)