Skip to content

Commit 9930d59

Browse files
authored
Merge pull request github#5124 from RasmusWL/typetracking-with-decorator
Python: Add test for type-tracking through decorators
2 parents 1c43505 + 1d25184 commit 9930d59

File tree

1 file changed

+35
-0
lines changed
  • python/ql/test/experimental/dataflow/typetracking

1 file changed

+35
-0
lines changed

python/ql/test/experimental/dataflow/typetracking/test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,41 @@ def test_import():
5656
y # $tracked
5757
mymodule.z # $tracked
5858

59+
60+
def to_inner_scope():
61+
x = tracked # $tracked
62+
def foo():
63+
y = x # $ MISSING: tracked
64+
return y # $ MISSING: tracked
65+
also_x = foo() # $ MISSING: tracked
66+
print(also_x) # $ MISSING: tracked
67+
68+
69+
def my_decorator(func):
70+
# This part doesn't make any sense in a normal decorator, but just shows how we
71+
# handle type-tracking
72+
73+
func() # $tracked
74+
75+
def wrapper():
76+
print("before function call")
77+
val = func() # $ MISSING: tracked
78+
print("after function call")
79+
return val # $ MISSING: tracked
80+
return wrapper
81+
82+
@my_decorator
83+
def get_tracked2():
84+
return tracked # $tracked
85+
86+
@my_decorator
87+
def unrelated_func():
88+
return "foo"
89+
90+
def use_funcs_with_decorators():
91+
x = get_tracked2() # $ MISSING: tracked
92+
y = unrelated_func()
93+
5994
# ------------------------------------------------------------------------------
6095

6196
def expects_int(x): # $int

0 commit comments

Comments
 (0)