Skip to content

Commit

Permalink
Avoid flagging missing whitespace for decorators (#4454)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored May 16, 2023
1 parent 7e0d018 commit d9c3f8e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/ruff/resources/test/fixtures/pycodestyle/E22.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def halves(n):
*a, b = (1, 2, 3)


@decorator
def squares(n):
return (i**2 for i in range(n))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ pub(crate) fn missing_whitespace_around_operator(
);

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 prev_kind = prev_token.kind();

// Check if the operator is used as a binary operator.
// Allow unary operators: -123, -x, +1.
// Allow argument unpacking: foo(*args, **kwargs)
// Allow decorators: @foo, @foo(1)
matches!(
prev_kind,
TokenKind::Rpar | TokenKind::Rsqb | TokenKind::Rbrace
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_ast/src/token_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl TokenKind {

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

#[inline]
Expand Down

0 comments on commit d9c3f8e

Please sign in to comment.