Skip to content
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

Avoid E203 for f-string debug expression #12024

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,7 @@

#: E203:1:13
f"{ham[lower + 1 :, "columnname"]}"

#: Okay: https://github.com/astral-sh/ruff/issues/12023
f"{x = :.2f}"
f"{(x) = :.2f}"
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ':'

Expand All @@ -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