Thomas Grainger <[email protected]> added the comment:
This is the output:
```
Traceback (most recent call last):
File "/home/graingert/projects/close.py", line 5, in foo
yield
File "/home/graingert/projects/close.py", line 12, in <module>
raise StartIrritation
__main__.StartIrritation
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/graingert/projects/close.py", line 11, in <module>
with foo():
File "/usr/lib/python3.10/contextlib.py", line 151, in __exit__
self.gen.throw(type, value, traceback)
RuntimeError: generator raised StopIteration
```
Note that this was fixed in @contextlib.asynccontextmanager
```
import asyncio
import contextlib
@contextlib.asynccontextmanager
async def foo():
yield
class StartIrritation(StopIteration):
pass
async def amain():
try:
async with foo():
raise StartIrritation
except StartIrritation:
print("good")
except RuntimeError:
print("bad")
asyncio.run(amain())
```
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44566>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com