-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
__context__ for yields inside except clause #69869
Comments
In the below snippet, SubError will propagate with __context__ set to None, instead of MainError. Maybe this isn't a bug? class MainError(Exception): pass
class SubError(Exception): pass
def main():
try:
raise MainError()
except MainError:
yield
coro = main()
coro.send(None)
coro.throw(SubError()) |
This is due to the fact that Python 3 added the ability to define only __eq__ and get a free __ne__ defined. If my memory serves me right, functools.total_ordering was added in 3.2 and then backported to 2.x - where the relationship with __eq__ and __ne__ is not present. total_ordering doesn't do anything to touch __ne__ as it expects Python itself to do so (which it doesn't in 2.x). |
Oops, that was *completely* the wrong issue. I apologize for the noise. |
I now don't think this is a bug. In the above example, SubError is instantiated outside of Closing this issue with 'not a bug'. |
I disagree with the stated reason for closing this, because in general, implicit context chaining doesn't care about where the exception was instantiated, only where it was raised. For example: ----- err = ValueError()
try:
raise KeyError
except Exception:
raise err Prints: ----- Traceback (most recent call last):
File "/tmp/bar.py", line 3, in <module>
raise KeyError
KeyError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/bar.py", line 5, in <module>
raise err
ValueError I would expect 'gen.throw(OBJ)' to be equivalent to doing 'raise OBJ' inside the generator, and raise does set __context__. |
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: