Avoid flagging missing whitespace for decorators (#4454)

This commit is contained in:
Charlie Marsh 2023-05-16 13:15:01 -04:00 committed by GitHub
parent 7e0d018b35
commit d9c3f8e249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View file

@ -160,6 +160,7 @@ if alpha[:-i]:
*a, b = (1, 2, 3) *a, b = (1, 2, 3)
@decorator
def squares(n): def squares(n):
return (i**2 for i in range(n)) return (i**2 for i in range(n))

View file

@ -86,13 +86,19 @@ pub(crate) fn missing_whitespace_around_operator(
); );
NeedsSpace::from(!slash_in_func) NeedsSpace::from(!slash_in_func)
} else if kind.is_unary() || kind == TokenKind::DoubleStar { } else if kind.is_unary()
|| matches!(
kind,
TokenKind::Star | TokenKind::DoubleStar | TokenKind::At
)
{
let is_binary = prev_token.map_or(false, |prev_token| { let is_binary = prev_token.map_or(false, |prev_token| {
let prev_kind = prev_token.kind(); let prev_kind = prev_token.kind();
// Check if the operator is used as a binary operator. // Check if the operator is used as a binary operator.
// Allow unary operators: -123, -x, +1. // Allow unary operators: -123, -x, +1.
// Allow argument unpacking: foo(*args, **kwargs) // Allow argument unpacking: foo(*args, **kwargs)
// Allow decorators: @foo, @foo(1)
matches!( matches!(
prev_kind, prev_kind,
TokenKind::Rpar | TokenKind::Rsqb | TokenKind::Rbrace TokenKind::Rpar | TokenKind::Rsqb | TokenKind::Rbrace

View file

@ -174,7 +174,7 @@ impl TokenKind {
#[inline] #[inline]
pub const fn is_unary(&self) -> bool { pub const fn is_unary(&self) -> bool {
matches!(self, TokenKind::Plus | TokenKind::Minus | TokenKind::Star) matches!(self, TokenKind::Plus | TokenKind::Minus)
} }
#[inline] #[inline]