mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 10:01:15 +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)
|
*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))
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue