-
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
unnecessary-literal-within-tuple-call
(C409) rule transforms single element list literals incorrectly
#10323
Comments
unnecessary-literal-within-tuple-call
(C409) rule fixes single element tuples incorrectlyunnecessary-literal-within-tuple-call
(C409) rule fixes zero and single element lists incorrectly
unnecessary-literal-within-tuple-call
(C409) rule fixes zero and single element lists incorrectlyunnecessary-literal-within-tuple-call
(C409) rule transforms single element list literals incorrectly
Thanks for the report! |
@zanieb Hi! |
Go for it @WindowGenerator. |
I don't know much about Ruff internals but it feels like it might be safer to take the approach of transforming and then rendering the AST, rather than replacing specific string indexes, since the latter is vulnerable to producing invalid or incorrect code in this fashion. |
Yeah, we have a |
We should just add this case to the fix. Text-based fixes are preferable because they preserve all trivia. (This fix used to use LibCST but we intentionally changed it because it’s slow and we want to remove our LibCST dependency altogether eventually.) I think there was just a misunderstanding on what the fix is supposed to do based on the comment above it in the code, which led to this oversight. |
…essary-literal-within-tuple-call)
…essary-literal-within-tuple-call)
…essary-literal-within-tuple-call)
…essary-literal-within-tuple-call)
Fixed by #10491. |
The
unnecessary-literal-within-tuple-call
(C409) rule detects the violation here:ruff check --fix --unsafe-fixes
fails to transform the code correctly, resulting in this, which is not a tuple:(1)
Instead it should transform the code to:
(1,)
Environment:
% ruff --version ruff 0.3.2 % cat pyproject.toml [tool.ruff] lint.select = [ "C4" ]
The text was updated successfully, but these errors were encountered: