mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
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:
@@ -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__"])
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user