Allow whitespace around colon in slices for whitespace-before-punctuation (E203)#8654
Allow whitespace around colon in slices for whitespace-before-punctuation (E203)#8654charliermarsh merged 1 commit intomainfrom
whitespace-before-punctuation (E203)#8654Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| E203 | 132 | 0 | 132 | 0 | 0 |
e112f61 to
8816092
Compare
| #: Okay | ||
| release_lines = history_file_lines[history_file_lines.index('## Unreleased') + 1: -1] |
There was a problem hiding this comment.
Wouldn't this now be not okay, since the spacing is different on the other side?
There was a problem hiding this comment.
The intent was to allow either this or the variant with the space.
| TokenKind::FStringStart => fstrings += 1, | ||
| TokenKind::FStringEnd => fstrings = fstrings.saturating_sub(1), | ||
| TokenKind::Lsqb if fstrings == 0 => { | ||
| brackets.push(kind); |
There was a problem hiding this comment.
I don't fully understand what has changed or how the new detection should work, which is why I'm unable to come up with a good example.
Is it possible that this change does not work as intended for parenthesized expressions inside f-strings because they are in between the start end token (fstrings > 0)?
f"start of f-string {a[(the_paren_logic) :b]} end of fstring"| TokenKind::Lsqb if fstrings == 0 => { | ||
| brackets.push(kind); | ||
| } | ||
| TokenKind::Rsqb if fstrings == 0 => { | ||
| brackets.pop(); | ||
| } | ||
| TokenKind::Lbrace if fstrings == 0 => { | ||
| brackets.push(kind); | ||
| } | ||
| TokenKind::Rbrace if fstrings == 0 => { | ||
| brackets.pop(); | ||
| } |
There was a problem hiding this comment.
Nit
| TokenKind::Lsqb if fstrings == 0 => { | |
| brackets.push(kind); | |
| } | |
| TokenKind::Rsqb if fstrings == 0 => { | |
| brackets.pop(); | |
| } | |
| TokenKind::Lbrace if fstrings == 0 => { | |
| brackets.push(kind); | |
| } | |
| TokenKind::Rbrace if fstrings == 0 => { | |
| brackets.pop(); | |
| } | |
| TokenKind::Lsqb | TokenKind::Lbrace if fstrings == 0 => { | |
| brackets.push(kind); | |
| } | |
| TokenKind::Rsqb | TokenKind::Rbrace if fstrings == 0 => { | |
| brackets.pop(); | |
| } |
| && brackets | ||
| .last() | ||
| .is_some_and(|kind| matches!(kind, TokenKind::Lsqb)) |
There was a problem hiding this comment.
Nit:
brackets.last() == Some(TokenKind::Lsqb)
Summary
This PR makes
whitespace-before-punctuation(E203) compatible with the formatter by relaxing the rule a bit, as compared to the pycodestyle implementation. It's also more consistent with PEP 8, which says:Closes #7259.
Closes #8642.
Test Plan
cargo test