-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gen.throw() with multiple yield froms skips intermediate exceptions #84871
Comments
Here is another gen.throw() exception chain example similar to the examples in bpo-29587: https://bugs.python.org/issue29587 def f():
yield
def g():
try:
raise RuntimeError('a')
except Exception as exc:
print(f'handling: {exc!r}')
yield from f()
def h():
try:
raise RuntimeError('b')
except Exception as exc:
print(f'handling: {exc!r}')
yield from g()
gen = h()
gen.send(None)
gen.throw(ValueError) Output: handling: RuntimeError('b')
handling: RuntimeError('a')
Traceback (most recent call last):
File "/.../test.py", line 13, in h
raise RuntimeError('b')
RuntimeError: b
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/.../test.py", line 20, in <module>
gen.throw(ValueError)
File "/.../test.py", line 16, in h
yield from g()
File "/.../test.py", line 9, in g
yield from f()
File "/.../test.py", line 2, in f
yield
ValueError The issue is that "RuntimeError: a" is skipped. It should also appear in the exception chain. I believe this has the same root cause as bpo-29590: https://bugs.python.org/issue29590 |
calling click to expandimport sys
def outer():
try:
raise RuntimeError("raised by outer")
except Exception:
try:
yield from middle()
finally:
val_err = sys.exc_info()[1]
assert isinstance(val_err, ValueError)
print(
"outer:"
f"\n\t{val_err.__context__=} (should be RE('raised by middle'))"
f"\n\t{val_err.__context__.__context__=} (should be RE('raised by outer'))"
)
def middle():
try:
raise RuntimeError("raised by middle")
except Exception:
try:
yield from inner()
finally:
val_err = sys.exc_info()[1]
assert isinstance(val_err, ValueError)
print(
"middle:"
f"\n\t{val_err.__context__=} (should be RE('raised by middle'))"
f"\n\t{val_err.__context__.__context__=} (should be RE('raised by outer'))"
)
def inner():
yield
gen = outer()
gen.send(None)
gen.throw(ValueError) output:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: