[issue44594] AsyncExitStack.enter_async_context() is mishandling exception __context__
John Belmonte
report at bugs.python.org
Mon Jul 12 02:33:45 EDT 2021
John Belmonte <john at neggie.net> added the comment:
[reposting the example, with source]
example:
class MyException(Exception):
pass
@contextmanager
def my_cm():
try:
yield
except BaseException:
exc = MyException()
try:
raise exc
finally:
exc.__context__ = None
print('\n=== `with` statement ===')
try:
with my_cm():
assert False
except BaseException as e:
traceback.print_exc()
print('\n=== enter_context() ===')
try:
with ExitStack() as stack:
stack.enter_context(my_cm())
assert False
except BaseException as e:
traceback.print_exc()
output:
=== `with` statement ===
Traceback (most recent call last):
File "exit_stack_test.py", line 251, in <module>
assert False
File "/.../python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "exit_stack_test.py", line 244, in my_cm
raise exc
MyException
=== enter_context() ===
Traceback (most recent call last):
File "exit_stack_test.py", line 240, in my_cm
yield
File "exit_stack_test.py", line 259, in <module>
assert False
AssertionError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "exit_stack_test.py", line 259, in <module>
assert False
File "/.../python3.7/contextlib.py", line 524, in __exit__
raise exc_details[1]
File "/.../python3.7/contextlib.py", line 509, in __exit__
if cb(*exc_details):
File "/.../python3.7/contextlib.py", line 377, in _exit_wrapper
return cm_exit(cm, exc_type, exc, tb)
File "/.../python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "exit_stack_test.py", line 244, in my_cm
raise exc
MyException
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44594>
_______________________________________
More information about the Python-bugs-list
mailing list