-
Notifications
You must be signed in to change notification settings - Fork 295
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
raise_from does not behave exactly like raise from #141
Comments
Just confirming that ver 0.15.0 still is buggy. And the consequences are not neglible since the root of the error is lost. |
Thanks for the feedback, Kostis! I think we've fixed now in v0.16.0 thanks to a new |
My apologies, I cannot answer your questions - you see, lately have started moving away from py2/3 code towards py3-only code. The compatibility debt was too great to curry. I'm very grateful for your efforts on this library. |
I have a potentially related problem with raise_from, specifically the behavior of native python3try:
try:
try:
raise Exception('foo')
except Exception as foo:
raise Exception('bar') from foo
except Exception as bar:
raise bar from Exception('quux')
except Exception as bar_quux:
last = bar_quux
print(last.args[0] == 'bar')
print(last.__cause__.args[0] == 'quux')
print(last.__context__.args[0] == 'foo')
print(last.__context__.args[0]) output:
using raise_fromfrom future.utils import raise_from
try:
try:
try:
raise Exception('foo')
except Exception as foo:
raise_from(Exception('bar'), foo)
except Exception as bar:
raise_from(bar, Exception('quux'))
except Exception as bar_quux:
last = bar_quux
print(last.args[0] == 'bar')
print(last.__cause__.args[0] == 'quux')
print(last.__context__.args[0] == 'foo')
print(last.__context__.args[0]) python3 output:
python2 output:
so basically, the I think I have an appropriate fix in: Stelminator@42cee74 which is just: - e.__context__ = sys.exc_info()[1]
+ if not hasattr(e, '__context__'):
+ e.__context__ = sys.exc_info()[1] |
I suppose that's still not quite complete: try:
try:
raise Exception('foo')
except Exception as foo:
try:
raise Exception('bar') from foo
except Exception as bar:
print(bar.__context__)
raise foo from bar
except Exception as foo:
wat = foo
print(wat.__context__.__context__)
#python2 with above fix
try:
try:
raise Exception('foo')
except Exception as foo:
try:
raise_from(Exception('bar'), foo)
except Exception as bar:
print(bar.__context__)
raise_from(foo, bar)
except Exception as foo:
wat = foo
print(wat.__context__.__context__)
Edit: I this actually might be a bug in python3. I don't think |
crosslink to my report to python bug tracker: http://bugs.python.org/issue31213 |
Cross-link to what looks (at first glance) to be a similar problem in |
Here's a bit of sample code from [https://www.python.org/dev/peps/pep-3134/](PEP 3134):
This, of course, does not work on Python 2. Using Python 3 I get the following output:
When using
raise_from
for Python2 compatibilitythis output (still with Python3) changes to:
Note that the traceback and exception information are missing from the
FileNotFoundError
.The text was updated successfully, but these errors were encountered: