fix(defines): resolve package-level from-import symbols to the package module

This commit is contained in:
TermiNexus committed 2026-10-26 18:11:51 +08:00
1 parent a2e9b1848e
commit edd9b1c151
1 file changed
+7 -3
+7 -3
View File
@@ -735,8 +735,11 @@ novirtual class ImportsGenMixin:
if alias.asname is not None:
local_name = alias.asname
orig_name = alias.name
# For `from . import Y`, _resolve_relative_module returns the package name
# but Y is a submodule, so map local_name -> the full submodule name.
# For `from . import Y`, _resolve_relative_module returns the package name.
# Y may be a real submodule (target package.Y) or a package __init__ symbol
# such as `JSON_NULL` (target the package itself). Only append the name
# when it denotes a submodule; otherwise the DefineT/global lives in the
# package vpi and the synthetic `package.Y` module does not exist.
fi_target: str = resolved
if impf.module is None and resolved is not None:
fl_t: sizet = string.strlen(resolved)
@@ -746,7 +749,8 @@ novirtual class ImportsGenMixin:
string.strcpy(jb_t, resolved)
jb_t[fl_t] = '.'
string.strcpy(jb_t + fl_t + 1, alias.name)
fi_target = jb_t
if StubMergerStore.LookupSha1ByModName(jb_t) is not None or self._is_local_module_file(alias.name) != 0:
fi_target = jb_t
trans._from_imports = self.add_from_import(trans.Pool, trans._from_imports, local_name, fi_target, orig_name)
# Static symbols (forbidden cross-module): `from mod import name` hitting one
# fail-fasts. Logic stays in _CheckStaticFromImport (inlining breaks inference).