circuitpython/tests/cpydiff/core_generator_noexit.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
465 B
Python
Raw Permalink Normal View History

"""
categories: Core,Generator
description: Context manager __exit__() not called in a generator which does not run to completion
cause: Unknown
workaround: Unknown
"""
2021-03-15 09:57:36 -04:00
class foo(object):
def __enter__(self):
2021-03-15 09:57:36 -04:00
print("Enter")
def __exit__(self, *args):
2021-03-15 09:57:36 -04:00
print("Exit")
def bar(x):
with foo():
while True:
x += 1
yield x
2021-03-15 09:57:36 -04:00
def func():
g = bar(0)
for _ in range(3):
print(next(g))
2021-03-15 09:57:36 -04:00
func()