Skip to content

Commit 883bd9f

Browse files
committed
Python: Add test for type-tracking with yield
1 parent 80c5e1e commit 883bd9f

File tree

1 file changed

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

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,32 @@ def other_name(self):
195195
def with_global_modifier(self):
196196
global some_value
197197
print(some_value) # $ tracked
198+
199+
# ------------------------------------------------------------------------------
200+
# yield
201+
# ------------------------------------------------------------------------------
202+
203+
def yielding_function():
204+
x = tracked # $ tracked
205+
yield x # $ tracked
206+
207+
def test_yield():
208+
for x in yielding_function(): # $ MISSING: tracked
209+
print(x) # $ MISSING: tracked
210+
211+
gen = yielding_function()
212+
y = next(gen) # $ MISSING: tracked
213+
print(y) # $ MISSING: tracked
214+
215+
216+
# see https://docs.python.org/3.11/library/contextlib.html#contextlib.contextmanager
217+
from contextlib import contextmanager
218+
219+
@contextmanager
220+
def managed_resource():
221+
x = tracked # $ tracked
222+
yield x # $ tracked
223+
224+
def test_context_manager():
225+
with managed_resource() as x: # $ MISSING: tracked
226+
print(x) # $ MISSING: tracked

0 commit comments

Comments
 (0)