-
Notifications
You must be signed in to change notification settings - Fork 911
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
return in finally swallows exceptions #651
Comments
Hi @iritkatriel, thanks for your suggestion. I'm not sure about the original intention behind this line but also suspect that it is supposed to suppress all exceptions. I added except BaseException:
pass in #653, is this what you had in mind? |
Then you don't need the finally clause anymore. Just have the return dedented to the level of the |
I could be wrong, but I'm fairly confident that the intention was just to catch def wraps(fun, namestr="{fun}", docstr="{doc}", **kwargs):
def _wraps(f):
try:
f.__name__ = namestr.format(fun=get_name(fun), **kwargs)
f.__doc__ = docstr.format(fun=get_name(fun), doc=get_doc(fun), **kwargs)
except AttributeError: pass
return f
return _wraps I'm not sure why the function was written in the way it was. |
In
autograd/autograd/wrap_util.py
Line 36 in 195e8d8
return
statement in afinally
block, which would swallow any in-flight exception.This means that if an unhandled exception (including a
BaseException
such asKeyboardInterrupt
) is raised from thetry
body, it will not propagate on as expected.If the intention is to suppress all exceptions, I would propose to make this clear by using "except BaseException".
See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.
The text was updated successfully, but these errors were encountered: