mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
48 lines
1.3 KiB
Plaintext
48 lines
1.3 KiB
Plaintext
import python
|
|
import utils.test.InlineExpectationsTest
|
|
import semmle.python.dataflow.new.DataFlow
|
|
import semmle.python.dataflow.new.internal.ImportResolution
|
|
|
|
private class ImmediateModuleRef extends DataFlow::Node {
|
|
Module mod;
|
|
string alias;
|
|
|
|
ImmediateModuleRef() {
|
|
this = ImportResolution::getImmediateModuleReference(mod) and
|
|
not mod.getName() in ["__future__", "trace"] and
|
|
this.asExpr() = any(Alias a | alias = a.getAsname().(Name).getId()).getAsname()
|
|
}
|
|
|
|
Module getModule() { result = mod }
|
|
|
|
string getAsname() { result = alias }
|
|
}
|
|
|
|
module ImportTest implements TestSig {
|
|
string getARelevantTag() { result = "imports" }
|
|
|
|
predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(ImmediateModuleRef ref |
|
|
tag = "imports" and
|
|
location = ref.getLocation() and
|
|
value = ref.getModule().getName() and
|
|
element = ref.toString()
|
|
)
|
|
}
|
|
}
|
|
|
|
module AliasTest implements TestSig {
|
|
string getARelevantTag() { result = "as" }
|
|
|
|
predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(ImmediateModuleRef ref |
|
|
tag = "as" and
|
|
location = ref.getLocation() and
|
|
value = ref.getAsname() and
|
|
element = ref.toString()
|
|
)
|
|
}
|
|
}
|
|
|
|
import MakeTest<MergeTests<ImportTest, AliasTest>>
|