[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +25590
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27024

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


Thomas Grainger  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 
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 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


New submission from Thomas Grainger :

https://bugs.python.org/issue1462485


import contextlib

@contextlib.contextmanager
def foo():
yield

class StartIrritation(StopIteration):
pass


with foo():
raise StartIrritation

--
messages: 396979
nosy: graingert, ncoghlan, yselivanov
priority: normal
severity: normal
status: open
title: StopIteration subclass raised in body of 'with' statement suppressed
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com