mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-07 10:40:16 +00:00
* 通过引发py_call错误覆盖相关调用者的ok==false分支 * Revert "通过引发py_call错误覆盖相关调用者的ok==false分支" This reverts commit 36dc0b5d81a02a83dfdeca2d4d6d265f5f793b4b. * add test * rename test files * fix bugs * fix bugs
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()
|
|
|
|
|