mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 17:41:12 +00:00
Avoid flagging missing whitespace for decorators (#4454)
This commit is contained in:
parent
7e0d018b35
commit
d9c3f8e249
3 changed files with 9 additions and 2 deletions
|
@ -160,6 +160,7 @@ if alpha[:-i]:
|
|||
*a, b = (1, 2, 3)
|
||||
|
||||
|
||||
@decorator
|
||||
def squares(n):
|
||||
return (i**2 for i in range(n))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue