Skip to content

Commit 66c3529

Browse files
committed
Python: Fix import * from __init__.py files
1 parent df6039d commit 66c3529

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/ImportResolution.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ module ImportResolution {
167167
)
168168
}
169169

170+
/** Gets the module from which attributes are imported by `i`. */
170171
Module getModuleImportedByImportStar(ImportStar i) {
171-
isPreferredModuleForName(result.getFile(), i.getImportedModuleName())
172+
isPreferredModuleForName(result.getFile(), i.getImportedModuleName() + ["", ".__init__"])
172173
}
173174

174175
/**

python/ql/test/experimental/import-resolution/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def local_import():
8787

8888
# check that import * from an __init__ file works
8989
from package.subpackage2 import *
90-
check("subpackage2_attr", subpackage2_attr, "subpackage2_attr", globals()) #$ MISSING: prints=subpackage2_attr
90+
check("subpackage2_attr", subpackage2_attr, "subpackage2_attr", globals()) #$ prints=subpackage2_attr
9191

9292

9393
exit(__file__)

0 commit comments

Comments
 (0)