python: Move the rewrite out to Scope.qll

This commit is contained in:
Rasmus Lerchedahl Petersen
2024-02-20 10:39:29 +01:00
parent de727bf1b5
commit 22e72d2fed

View File

@@ -1,4 +1,16 @@
import python
private import semmle.python.dataflow.new.internal.ImportResolution
/**
* Gets a name exported by module `m`, that is the names that will be added to a namespace by 'from this-module import *'.
*
* This aims to be the same as m.getAnExport(), but without using the points-to machinery.
*/
private string getAModuleExport(Module m) {
py_exports(m, result)
or
ImportResolution::module_export(m, result, _)
}
/**
* A Scope. A scope is the lexical extent over which all identifiers with the same name refer to the same variable.
@@ -74,9 +86,9 @@ class Scope extends Scope_ {
or
exists(Module m | m = this.getEnclosingScope() and m.isPublic() |
/* If the module has an __all__, is this in it */
not exists(m.getAnExport())
not exists(getAModuleExport(m))
or
m.getAnExport() = this.getName()
getAModuleExport(m) = this.getName()
)
or
exists(Class c | c = this.getEnclosingScope() |