Skip to content

Commit 6ba39d5

Browse files
committed
Python: Add import regression for re-exported things
1 parent 6a5eebe commit 6ba39d5

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

python/ql/test/experimental/import-resolution/ModuleExport.expected

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
| bar | print | trace.py:7:1:7:27 | ControlFlowNode for FunctionExpr |
4949
| bar | print_function | trace.py:1:24:1:37 | ControlFlowNode for ImportMember |
5050
| bar | status | trace.py:23:1:23:13 | ControlFlowNode for FunctionExpr |
51+
| baz | __all__ | trace.py:52:11:52:46 | ControlFlowNode for List |
52+
| baz | __file__ | baz.py:2:7:2:14 | ControlFlowNode for __file__ |
53+
| baz | __file__ | baz.py:6:6:6:13 | ControlFlowNode for __file__ |
54+
| baz | _indent_level | trace.py:3:17:3:17 | ControlFlowNode for IntegerLiteral |
55+
| baz | _print | trace.py:5:10:5:14 | ControlFlowNode for print |
56+
| baz | _status | trace.py:21:11:21:11 | ControlFlowNode for IntegerLiteral |
57+
| baz | baz_attr | baz.py:4:12:4:21 | ControlFlowNode for Str |
58+
| baz | check | trace.py:26:1:26:61 | ControlFlowNode for FunctionExpr |
59+
| baz | enter | trace.py:11:1:11:21 | ControlFlowNode for FunctionExpr |
60+
| baz | exit | trace.py:16:1:16:20 | ControlFlowNode for FunctionExpr |
61+
| baz | print | trace.py:7:1:7:27 | ControlFlowNode for FunctionExpr |
62+
| baz | print_function | trace.py:1:24:1:37 | ControlFlowNode for ImportMember |
63+
| baz | status | trace.py:23:1:23:13 | ControlFlowNode for FunctionExpr |
5164
| foo | __all__ | trace.py:52:11:52:46 | ControlFlowNode for List |
5265
| foo | __file__ | foo.py:2:7:2:14 | ControlFlowNode for __file__ |
5366
| foo | __file__ | foo.py:14:6:14:13 | ControlFlowNode for __file__ |
@@ -95,7 +108,7 @@
95108
| if_then_else_refined | status | trace.py:23:1:23:13 | ControlFlowNode for FunctionExpr |
96109
| main | __all__ | trace.py:52:11:52:46 | ControlFlowNode for List |
97110
| main | __file__ | main.py:24:7:24:14 | ControlFlowNode for __file__ |
98-
| main | __file__ | main.py:103:6:103:13 | ControlFlowNode for __file__ |
111+
| main | __file__ | main.py:107:6:107:13 | ControlFlowNode for __file__ |
99112
| main | __file__ | package/subpackage2/__init__.py:2:7:2:14 | ControlFlowNode for __file__ |
100113
| main | __file__ | package/subpackage2/__init__.py:6:6:6:13 | ControlFlowNode for __file__ |
101114
| main | _indent_level | trace.py:3:17:3:17 | ControlFlowNode for IntegerLiteral |
@@ -130,6 +143,7 @@
130143
| main | print_function | main.py:21:24:21:37 | ControlFlowNode for ImportMember |
131144
| main | print_function | trace.py:1:24:1:37 | ControlFlowNode for ImportMember |
132145
| main | refined | main.py:97:8:97:14 | ControlFlowNode for ImportExpr |
146+
| main | simplistic_reexport | main.py:103:8:103:26 | ControlFlowNode for ImportExpr |
133147
| main | status | trace.py:23:1:23:13 | ControlFlowNode for FunctionExpr |
134148
| main | subpackage2_attr | package/subpackage2/__init__.py:4:20:4:37 | ControlFlowNode for Str |
135149
| main | subpackage_attr | main.py:46:6:46:23 | ControlFlowNode for ImportExpr |
@@ -219,6 +233,25 @@
219233
| refined | print | trace.py:7:1:7:27 | ControlFlowNode for FunctionExpr |
220234
| refined | print_function | trace.py:1:24:1:37 | ControlFlowNode for ImportMember |
221235
| refined | status | trace.py:23:1:23:13 | ControlFlowNode for FunctionExpr |
236+
| simplistic_reexport | __all__ | trace.py:52:11:52:46 | ControlFlowNode for List |
237+
| simplistic_reexport | __file__ | baz.py:2:7:2:14 | ControlFlowNode for __file__ |
238+
| simplistic_reexport | __file__ | baz.py:6:6:6:13 | ControlFlowNode for __file__ |
239+
| simplistic_reexport | __file__ | simplistic_reexport.py:4:7:4:14 | ControlFlowNode for __file__ |
240+
| simplistic_reexport | __file__ | simplistic_reexport.py:19:6:19:13 | ControlFlowNode for __file__ |
241+
| simplistic_reexport | _indent_level | trace.py:3:17:3:17 | ControlFlowNode for IntegerLiteral |
242+
| simplistic_reexport | _print | trace.py:5:10:5:14 | ControlFlowNode for print |
243+
| simplistic_reexport | _status | trace.py:21:11:21:11 | ControlFlowNode for IntegerLiteral |
244+
| simplistic_reexport | bar_attr | simplistic_reexport.py:6:6:6:8 | ControlFlowNode for ImportExpr |
245+
| simplistic_reexport | bar_attr | simplistic_reexport.py:6:17:6:24 | ControlFlowNode for ImportMember |
246+
| simplistic_reexport | bar_attr | simplistic_reexport.py:9:12:9:24 | ControlFlowNode for Str |
247+
| simplistic_reexport | baz_attr | baz.py:4:12:4:21 | ControlFlowNode for Str |
248+
| simplistic_reexport | baz_attr | simplistic_reexport.py:16:12:16:24 | ControlFlowNode for Str |
249+
| simplistic_reexport | check | trace.py:26:1:26:61 | ControlFlowNode for FunctionExpr |
250+
| simplistic_reexport | enter | trace.py:11:1:11:21 | ControlFlowNode for FunctionExpr |
251+
| simplistic_reexport | exit | trace.py:16:1:16:20 | ControlFlowNode for FunctionExpr |
252+
| simplistic_reexport | print | trace.py:7:1:7:27 | ControlFlowNode for FunctionExpr |
253+
| simplistic_reexport | print_function | trace.py:1:24:1:37 | ControlFlowNode for ImportMember |
254+
| simplistic_reexport | status | trace.py:23:1:23:13 | ControlFlowNode for FunctionExpr |
222255
| trace | __all__ | trace.py:52:11:52:46 | ControlFlowNode for List |
223256
| trace | _indent_level | trace.py:3:17:3:17 | ControlFlowNode for IntegerLiteral |
224257
| trace | _print | trace.py:5:10:5:14 | ControlFlowNode for print |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from trace import *
2+
enter(__file__)
3+
4+
baz_attr = "baz_attr"
5+
6+
exit(__file__)

python/ql/test/experimental/import-resolution/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def local_import():
100100
import if_then_else_refined # $ imports=if_then_else_refined as=if_then_else_refined
101101
check("if_then_else_refined.src", if_then_else_refined.src, if_then_else_refined.src, globals()) #$ prints=SOURCE
102102

103+
import simplistic_reexport # $ imports=simplistic_reexport as=simplistic_reexport
104+
check("simplistic_reexport.bar_attr", simplistic_reexport.bar_attr, "overwritten", globals()) #$ prints=overwritten SPURIOUS: prints="<module bar>" prints=bar_attr
105+
check("simplistic_reexport.baz_attr", simplistic_reexport.baz_attr, "overwritten", globals()) #$ prints=overwritten SPURIOUS: prints=baz_attr
106+
103107
exit(__file__)
104108

105109
print()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# we might consider anything imported to also be exported, but this is not the case
2+
3+
from trace import *
4+
enter(__file__)
5+
6+
from bar import bar_attr
7+
check("bar_attr", bar_attr, "bar_attr", globals()) #$ prints=bar_attr
8+
9+
bar_attr = "overwritten"
10+
check("bar_attr", bar_attr, "overwritten", globals()) #$ prints=overwritten
11+
12+
13+
from baz import *
14+
check("baz_attr", baz_attr, "baz_attr", globals()) #$ MISSING: prints=baz_attr
15+
16+
baz_attr = "overwritten"
17+
check("baz_attr", baz_attr, "overwritten", globals()) #$ prints=overwritten
18+
19+
exit(__file__)

0 commit comments

Comments
 (0)