-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow whitespace around colon in slices for whitespace-before-punctuation
(E203
)
#8654
Conversation
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this now be not okay, since the spacing is different on the other side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent was to allow either this or the variant with the space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay, interesting choice
let kind = token.kind(); | ||
match kind { | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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