Repository navigation
[flake8-logging-format] Avoid behavior changes and syntax errors in fixes (G004) - #27419
Conversation
|
ntBre
left a comment
There was a problem hiding this comment.
Thanks! This looks reasonable to me overall. I had one request about the tests, and then Codex found a couple of additional edge cases that we should also try to handle:
-
Keyword arguments can produce invalid code
import logging value = "sample" logging.warning(msg=(f"message: {value}"))
this produces
logging.warning(msg="message: %s", value)
with the keyword before the positional argument. I think the result just needs to be parenthesized, like we currently do on main: https://play.ruff.rs/4d6a3c7a-bb6b-4943-b73a-903beef076f7.
-
Comments can now be removed in a safe fix
import logging value = "sample" logging.warning( ( # Important explanation f"message: {value}" # Another important explanation ) )
This is okay overall, we just need to mark the fix unsafe in this case. We can check something like this:
ruff/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs
Lines 111 to 115 in 17a00de
This is one downside of using the generator, though. On main we preserve all the comments: https://play.ruff.rs/833dbeba-42c6-4782-ab5f-e1dedd15e7b8
flake8-logging-format] Avoid behavior changes and syntax errors in fixes (G004)
f1f4917 to
25ba8bc
Compare
hirehamir
left a comment
There was a problem hiding this comment.
You're welcome! I think adding the parentheses would result in different runtime behavior, but I did implement the other suggestions.
|
@ntBre are there any other changes I should make here? |
ntBre
left a comment
There was a problem hiding this comment.
Looks good to me, thank you! I just trimmed some of the comments a bit.
|
You're welcome! I'm happy to help. |
Summary
Fixes #20151
I authored the original fix in #19303. This improves that implementation.
Test Plan
I added a new fixture that covers multiple cases from the issue.