Python: Fix missing module resolution

This was due to bad manual magic: restricting the attribute name makes
sense when we're talking about submodules of a package, but it doesn't
when we're talking about reexported modules.

Also (hopefully) fixes the tests so that the Python 3-specific bits are
ignored under Python 2.
This commit is contained in:
Taus
2022-11-16 19:58:32 +00:00
parent 19261ecfbf
commit 81348049df
3 changed files with 37 additions and 10 deletions

View File

@@ -235,9 +235,12 @@ module ImportResolution {
result = ar
|
isPreferredModuleForName(m.getFile(), p.getPackageName() + "." + attr_name + ["", ".__init__"])
or
// This is also true for attributes that come from reexports.
module_reexport(p, attr_name, m)
)
or
// This is also true for attributes that come from reexports.
exists(Module reexporter, string attr_name |
result.(DataFlow::AttrRead).accesses(getModuleReference(reexporter), attr_name) and
module_reexport(reexporter, attr_name, m)
)
or
// Submodules that are implicitly defined with relative imports of the form `from .foo import ...`.