Hi,
I noticed that the exception handler does not catch an exception raised from the local generator. This seems to be a bug; Otherwise, it could be a design, but I’d like to hear some opinions before reporting it to the bug tracker.
This is the test code:
def g(n):
try:
def _g():
## return range(n) # ok: An error from range will be caught.
yield from range(n) # NG: A generator error can't be caught.
return _g()
except Exception as e:
print(e)
return []
print(list(g(None)))
which gives the following traceback message:
Traceback (most recent call last):
File "C:\usr\home\lib\python\test-py\py3_issue_gen2.py", line 23, in <module>
print(list(g(None)))
File "C:\usr\home\lib\python\test-py\py3_issue_gen2.py", line 16, in _g
yield from range(n) # NG: A generator error can't be caught.
TypeError: 'NoneType' object cannot be interpreted as an integer
Python 3.10.11