зеркало из https://github.com/github/codeql.git
Python: Add test for type-tracking with `yield`
This commit is contained in:
Родитель
80c5e1ea77
Коммит
883bd9f3b3
|
@ -195,3 +195,32 @@ class MyClass(object):
|
|||
def with_global_modifier(self):
|
||||
global some_value
|
||||
print(some_value) # $ tracked
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# yield
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
def yielding_function():
|
||||
x = tracked # $ tracked
|
||||
yield x # $ tracked
|
||||
|
||||
def test_yield():
|
||||
for x in yielding_function(): # $ MISSING: tracked
|
||||
print(x) # $ MISSING: tracked
|
||||
|
||||
gen = yielding_function()
|
||||
y = next(gen) # $ MISSING: tracked
|
||||
print(y) # $ MISSING: tracked
|
||||
|
||||
|
||||
# see https://docs.python.org/3.11/library/contextlib.html#contextlib.contextmanager
|
||||
from contextlib import contextmanager
|
||||
|
||||
@contextmanager
|
||||
def managed_resource():
|
||||
x = tracked # $ tracked
|
||||
yield x # $ tracked
|
||||
|
||||
def test_context_manager():
|
||||
with managed_resource() as x: # $ MISSING: tracked
|
||||
print(x) # $ MISSING: tracked
|
||||
|
|
Загрузка…
Ссылка в новой задаче