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: overrides return in except: #347

Closed
iritkatriel opened this issue Oct 28, 2024 · 1 comment
Closed

return in finally: overrides return in except: #347

iritkatriel opened this issue Oct 28, 2024 · 1 comment
Assignees
Milestone

Comments

@iritkatriel
Copy link

In

return self._apply_op_between_arrays(op, other, is_comparison=True)
the return in finally: will override the return NotImplemented in the except: clause, so I don't think this code does what it was intended to do.

>>> def f():
...     try:
...         1/0
...     except:
...         return 1
...     finally:
...         return 2
...         
>>> f()
2

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

@scott-griffiths
Copy link
Owner

Hmm, yes good point. I think this ended up like that after a bit of a refactor so it's not that clear what it's even supposed to do! It appears harmless but I'll fix it in the next release. Thanks.

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

No branches or pull requests

2 participants