Python: Add test for type-tracking with `yield`

This commit is contained in:
Rasmus Wriedt Larsen 2023-10-16 12:09:07 +02:00
Родитель 80c5e1ea77
Коммит 883bd9f3b3
Не найден ключ, соответствующий данной подписи
1 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -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