Skip to content

Commit e522009

Browse files
committed
Python: More complex import examples
We need some recursive unwinding to get all of these right
1 parent 00eec69 commit e522009

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# combination of refined and if_then_else
2+
3+
from trace import *
4+
enter(__file__)
5+
6+
class SOURCE(): pass
7+
8+
# definition based on "random" choice in this case it will always go the the if-branch,
9+
# but our analysis is not able to figure this out
10+
if eval("True"):
11+
src = SOURCE
12+
else:
13+
src = SOURCE
14+
15+
src.foo = 42
16+
17+
check("src", src, src, globals()) #$ prints=SOURCE
18+
19+
exit(__file__)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def local_import():
9595

9696
# check that refined definitions are handled correctly
9797
import refined # $ imports=refined as=refined
98-
check("refined.SOURCE", refined.SOURCE, refined.SOURCE, globals()) #$ prints=SOURCE
98+
check("refined.SOURCE", refined.SOURCE, refined.SOURCE, globals()) #$ MISSING: prints=SOURCE
99+
100+
import if_then_else_refined # $ imports=if_then_else_refined as=if_then_else_refined
101+
check("if_then_else_refined.src", if_then_else_refined.src, if_then_else_refined.src, globals()) #$ MISSING: prints=SOURCE
99102

100103
exit(__file__)
101104

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class SOURCE(object): pass
66
check("SOURCE", SOURCE, SOURCE, globals()) #$ prints=SOURCE
77

88
SOURCE.foo = 42
9+
SOURCE.bar = 43
10+
SOURCE.baz = 44
911

1012
check("SOURCE", SOURCE, SOURCE, globals()) #$ prints=SOURCE
1113

0 commit comments

Comments
 (0)