Skip to content

Commit 811426c

Browse files
committed
Python: Remove manual magic entirely
This was causing issues with imports with many "dots" in the name. Previously, the test added in this commit would not have the desired result for the `check` call.
1 parent 8ed8161 commit 811426c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ module ImportResolution {
231231
// Reading an attribute on a module may return a submodule (or subpackage).
232232
exists(DataFlow::AttrRead ar, Module p, string attr_name |
233233
ar.accesses(getModuleReference(p), attr_name) and
234-
attr_name = any(Module m0).getFile().getStem() and
235234
result = ar
236235
|
237236
isPreferredModuleForName(m.getFile(), p.getPackageName() + "." + attr_name + ["", ".__init__"])

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ def local_import():
6969
import package.subpackage #$ imports=package.__init__ as=package
7070
check("package.package_attr", package.package_attr, "package_attr", globals()) #$ prints=package_attr
7171

72+
# Deep imports
73+
import package.subpackage.submodule #$ imports=package.__init__ as=package
74+
check("package.subpackage.submodule.submodule_attr", package.subpackage.submodule.submodule_attr, "submodule_attr", globals()) #$ prints=submodule_attr
75+
76+
7277
if sys.version_info[0] == 3:
7378
# Importing from a namespace module.
7479
from namespace_package.namespace_module import namespace_module_attr

0 commit comments

Comments
 (0)