Skip to content

Commit

Permalink
Merge pull request #16883 from github/tausbn/python-fix-bad-join-in-i…
Browse files Browse the repository at this point in the history
…mport-resolution

Python: Fix bad join in `getImmediateModuleReference`
  • Loading branch information
RasmusWL authored Jul 3, 2024
2 parents dfc59a4 + 446dbf6 commit f9536e9
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ module ImportResolution {
)
}

/** Join-order helper for `getImmediateModuleReference`. */
pragma[nomagic]
private predicate module_reference_accesses(DataFlow::AttrRead ar, Module p, string attr_name) {
ar.accesses(getModuleReference(p), attr_name)
}

/**
* Gets a dataflow node that is an immediate reference to the module `m`.
*
Expand All @@ -294,16 +300,13 @@ module ImportResolution {
)
or
// 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
result = ar
|
exists(Module p, string attr_name | module_reference_accesses(result, p, attr_name) |
m = getModuleFromName(p.getPackageName() + "." + attr_name)
)
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_reference_accesses(result, reexporter, attr_name) and
module_reexport(reexporter, attr_name, m)
)
or
Expand Down

0 comments on commit f9536e9

Please sign in to comment.