Skip to content

Commit 80f5342

Browse files
committed
Python: Add import regression for if-then-else definitions
1 parent 180246b commit 80f5342

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from trace import *
2+
enter(__file__)
3+
4+
# definition based on "random" choice in this case it will always go the the if-branch,
5+
# but our analysis is not able to figure this out
6+
if eval("True"):
7+
if_then_else_defined = "if_defined"
8+
else:
9+
# we also check that nested if-then-else works, it would be easy to accidentally
10+
# only support _one_ level of nesting.
11+
if eval("True"):
12+
if_then_else_defined = "else_defined_1"
13+
else:
14+
if_then_else_defined = "else_defined_2"
15+
16+
exit(__file__)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def local_import():
8989
from package.subpackage2 import *
9090
check("subpackage2_attr", subpackage2_attr, "subpackage2_attr", globals()) #$ prints=subpackage2_attr
9191

92+
# check that definitions from within if-then-else are found
93+
from if_then_else import if_then_else_defined
94+
check("if_then_else_defined", if_then_else_defined, "if_defined", globals()) #$ MISSING: prints=if_defined prints=else_defined_1 prints=else_defined_2
9295

9396
exit(__file__)
9497

0 commit comments

Comments
 (0)