Skip to content
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

return in finally swallows exceptions #11304

Open
iritkatriel opened this issue Nov 6, 2024 · 0 comments
Open

return in finally swallows exceptions #11304

iritkatriel opened this issue Nov 6, 2024 · 0 comments

Comments

@iritkatriel
Copy link

iritkatriel commented Nov 6, 2024

In

return dt # noqa: B012
there is a return statement in a finally clause, which would swallow any in-flight exception.

Since except StopIteration two lines above explicitly swallows StopIteration exceptions, my guess is that the intention was not to also swallow all other exceptions. If it was, the code could be rewritten to make this clearer.

Similarly, in

return main_res[0] if main_res else main_obj
there is a return that would swallow any BaseException (including KeyboardInterrupt) where the except only explicitly swallows Exceptions.

See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant