Python: Add import * test

This test shows off a few things:

- transitive chains of `import *`
- multiple modules exporting the same name (to test for cross-talk)
This commit is contained in:
Taus
2021-11-26 13:12:10 +00:00
committed by GitHub
parent dc0b0445ed
commit 03b6ee3833
10 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from trois import *
print(foo)

View File

@@ -0,0 +1,3 @@
moduleVariables
reads
writes

View File

@@ -0,0 +1,12 @@
import python
import semmle.python.dataflow.new.DataFlow
query DataFlow::Node moduleVariables() { result instanceof DataFlow::ModuleVariableNode }
query predicate reads(DataFlow::Node fromNode, DataFlow::Node toNode) {
fromNode.(DataFlow::ModuleVariableNode).getARead() = toNode
}
query predicate writes(DataFlow::Node fromNode, DataFlow::Node toNode) {
fromNode = toNode.(DataFlow::ModuleVariableNode).getAWrite()
}

View File

@@ -0,0 +1 @@
from two import *

View File

@@ -0,0 +1,2 @@
from one import *
print(foo)

View File

@@ -0,0 +1,2 @@
from un import *
print(foo)

View File

@@ -0,0 +1 @@
foo = 5

View File

@@ -0,0 +1 @@
foo = 5

View File

@@ -0,0 +1,2 @@
from three import *
print(foo)

View File

@@ -0,0 +1 @@
from deux import *