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

Fix E203 false positive for slices in format strings #10280

Merged
merged 2 commits into from
Mar 7, 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
6 changes: 6 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@

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

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

#: E203:1:13
f"{ham[lower + 1 :, "columnname"]}"
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ pub(crate) fn extraneous_whitespace(line: &LogicalLine, context: &mut LogicalLin
match kind {
TokenKind::FStringStart => fstrings += 1,
TokenKind::FStringEnd => fstrings = fstrings.saturating_sub(1),
TokenKind::Lsqb if fstrings == 0 => {
TokenKind::Lsqb => {
brackets.push(kind);
}
TokenKind::Rsqb if fstrings == 0 => {
TokenKind::Rsqb => {
brackets.pop();
}
TokenKind::Lbrace if fstrings == 0 => {
TokenKind::Lbrace => {
brackets.push(kind);
}
TokenKind::Rbrace if fstrings == 0 => {
TokenKind::Rbrace => {
brackets.pop();
}
_ => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ E20.py:155:14: E203 [*] Whitespace before ':'
154 | #: E203:1:13
155 | ham[lower + 1 :, "columnname"]
| ^^ E203
156 |
157 | #: Okay
|
= help: Remove whitespace before ':'

Expand All @@ -260,3 +262,21 @@ E20.py:155:14: E203 [*] Whitespace before ':'
154 154 | #: E203:1:13
155 |-ham[lower + 1 :, "columnname"]
155 |+ham[lower + 1:, "columnname"]
156 156 |
157 157 | #: Okay
158 158 | f"{ham[lower +1 :, "columnname"]}"

E20.py:161:17: E203 [*] Whitespace before ':'
|
160 | #: E203:1:13
161 | f"{ham[lower + 1 :, "columnname"]}"
| ^^ E203
|
= help: Remove whitespace before ':'

ℹ Safe fix
158 158 | f"{ham[lower +1 :, "columnname"]}"
159 159 |
160 160 | #: E203:1:13
161 |-f"{ham[lower + 1 :, "columnname"]}"
161 |+f"{ham[lower + 1:, "columnname"]}"
Loading