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.
This commit is contained in:
Taus
2022-11-17 14:15:55 +00:00
parent 8ed8161d5c
commit 811426c586
2 changed files with 5 additions and 1 deletions

View File

@@ -231,7 +231,6 @@ module ImportResolution {
// Reading an attribute on a module may return a submodule (or subpackage).
exists(DataFlow::AttrRead ar, Module p, string attr_name |
ar.accesses(getModuleReference(p), attr_name) and
attr_name = any(Module m0).getFile().getStem() and
result = ar
|
isPreferredModuleForName(m.getFile(), p.getPackageName() + "." + attr_name + ["", ".__init__"])

View File

@@ -69,6 +69,11 @@ check("aliased_subpackage.subpackage_attr", aliased_subpackage.subpackage_attr,
import package.subpackage #$ imports=package.__init__ as=package
check("package.package_attr", package.package_attr, "package_attr", globals()) #$ prints=package_attr
# Deep imports
import package.subpackage.submodule #$ imports=package.__init__ as=package
check("package.subpackage.submodule.submodule_attr", package.subpackage.submodule.submodule_attr, "submodule_attr", globals()) #$ prints=submodule_attr
if sys.version_info[0] == 3:
# Importing from a namespace module.
from namespace_package.namespace_module import namespace_module_attr