mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
31 lines
470 B
Python
31 lines
470 B
Python
path = []
|
|
|
|
class A:
|
|
def __init__(self, x):
|
|
self.x = x
|
|
self.path = []
|
|
|
|
def __enter__(self):
|
|
path.append('enter')
|
|
return self.x
|
|
|
|
def __exit__(self, *args):
|
|
path.append('exit')
|
|
|
|
|
|
with A(123):
|
|
assert path == ['enter']
|
|
assert path == ['enter', 'exit']
|
|
|
|
path.clear()
|
|
|
|
with A(123) as a:
|
|
assert path == ['enter']
|
|
assert a == 123
|
|
path.append('in')
|
|
assert path == ['enter', 'in', 'exit']
|
|
|
|
path.clear()
|
|
|
|
|