mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:52:01 +00:00
Avoid E203
for f-string debug expression (#12024)
## Summary This PR fixes a bug where Ruff would raise `E203` for f-string debug expression. This isn't valid because whitespaces are important for debug expressions. fixes: #12023 ## Test Plan Add test case and make sure there are no snapshot changes.
This commit is contained in:
parent
7109214b57
commit
2853751344
3 changed files with 16 additions and 0 deletions
|
@ -273,6 +273,13 @@ pub(crate) fn extraneous_whitespace(line: &LogicalLine, context: &mut LogicalLin
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if fstrings > 0
|
||||
&& symbol == ':'
|
||||
&& matches!(prev_token, Some(TokenKind::Equal))
|
||||
{
|
||||
// Avoid removing any whitespace for f-string debug expressions.
|
||||
continue;
|
||||
}
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
WhitespaceBeforePunctuation { symbol },
|
||||
TextRange::at(token.start() - offset, offset),
|
||||
|
|
|
@ -331,6 +331,8 @@ E20.py:187:17: E203 [*] Whitespace before ':'
|
|||
186 | #: E203:1:13
|
||||
187 | f"{ham[lower + 1 :, "columnname"]}"
|
||||
| ^^ E203
|
||||
188 |
|
||||
189 | #: Okay: https://github.com/astral-sh/ruff/issues/12023
|
||||
|
|
||||
= help: Remove whitespace before ':'
|
||||
|
||||
|
@ -340,3 +342,6 @@ E20.py:187:17: E203 [*] Whitespace before ':'
|
|||
186 186 | #: E203:1:13
|
||||
187 |-f"{ham[lower + 1 :, "columnname"]}"
|
||||
187 |+f"{ham[lower + 1:, "columnname"]}"
|
||||
188 188 |
|
||||
189 189 | #: Okay: https://github.com/astral-sh/ruff/issues/12023
|
||||
190 190 | f"{x = :.2f}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue