-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
RET504
invalid autofix
#5909
Comments
Thanks for the report @tylerlaprade. It looks like perhaps we should not raise RET504 inside context managers? |
I think this is a special case as |
@dhruvmanila the problem is that any context manager could suppress exceptions, we can't really know. I agree that |
Oh jeez what an interesting case. |
Sourcery has been autofixing all my |
Shameless plug that Ruff can do it too 😂 https://beta.ruff.rs/docs/rules/suppressible-exception/ |
Ah, I do have |
#9673) ## Summary This review contains a fix for [RET504](https://docs.astral.sh/ruff/rules/unnecessary-assign/) (unnecessary-assign) The problem is that Ruff suggests combining a return statement inside contextlib.suppress. Even though it is an unsafe fix it might lead to an invalid code that is not equivalent to the original one. See: #5909 ## Test Plan ```bash cargo test ```
#9673) ## Summary This review contains a fix for [RET504](https://docs.astral.sh/ruff/rules/unnecessary-assign/) (unnecessary-assign) The problem is that Ruff suggests combining a return statement inside contextlib.suppress. Even though it is an unsafe fix it might lead to an invalid code that is not equivalent to the original one. See: #5909 ## Test Plan ```bash cargo test ```
This appears to be fixed in |
is autofixed to
These are not equivalent. The first one will always return
data
, either decoded or the original. The second will return the decoded data if there's no exception, otherwise, it will returnNone
. This introduced a bug into my code that I only caught from some miscellaneous Pyright type-checking far away from the autofix.The text was updated successfully, but these errors were encountered: