You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The COM812 rule is capable of breaking conditional statements within triple f-strings by converting the else-statement into a tuple (or a tuple containing the original tuple).
Of course you can use # noqa: COM812, though I think that linters should be incapable of breaking code.
MRE
(This example assumes the line should be split across multiple lines.)
Original mre.py:
x=f"""This is a test. {"Another sentence."ifTrueelse"Alternative route!"}"""print(x)
$ py test.py
This is a test. Another sentence.
$ ruff check mre.py
mre.py:4:25: COM812 [*] Trailing comma missing
Found 1 error.
[*] 1 fixable with the `--fix` option.
"Fixed" mre.py
x=f"""This is a test. {"Another sentence."ifTrueelse"Alternative route!",}"""print(x)
$ py test.py
This is a test. ('Another sentence.',)
$ ruff check mre.py
(Exit code 0)
I think it must be considering the curly braces as ContextType::Dict. It needs to take into account the new f-string tokens and skip if inside a f-string.
Activity
charliermarsh commentedon Nov 9, 2023
Thanks, I'll take a look at this!
dhruvmanila commentedon Nov 9, 2023
I think it must be considering the curly braces as
ContextType::Dict. It needs to take into account the new f-string tokens and skip if inside a f-string.charliermarsh commentedon Nov 9, 2023
@dhruvmanila - Feel free to fix if you're there, I won't get to it for a few hours.
charliermarsh commentedon Nov 9, 2023
Taking a look now.
Avoid inserting trailing commas within f-strings (#8574)
Consider the new f-string tokens for `flake8-commas` (#8582)
Avoid inserting trailing commas within f-strings (#8574)