mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:53 +00:00
[ruff
] Skip singleton starred expressions for incorrectly-parenthesized-tuple-in-subscript
(RUF031
) (#16083)
The index in subscript access like `d[*y]` will not be linted or autofixed with parentheses, even when `lint.ruff.parenthesize-tuple-in-subscript = true`. Closes #16077
This commit is contained in:
parent
a4c8c49ac2
commit
f30fac6326
3 changed files with 14 additions and 0 deletions
|
@ -42,3 +42,7 @@ import typing
|
||||||
type Y = typing.Literal[1, 2]
|
type Y = typing.Literal[1, 2]
|
||||||
Z: typing.TypeAlias = dict[int, int]
|
Z: typing.TypeAlias = dict[int, int]
|
||||||
class Foo(dict[str, int]): pass
|
class Foo(dict[str, int]): pass
|
||||||
|
|
||||||
|
# Skip tuples of length one that are single-starred expressions
|
||||||
|
# https://github.com/astral-sh/ruff/issues/16077
|
||||||
|
d[*x]
|
||||||
|
|
|
@ -42,3 +42,7 @@ import typing
|
||||||
type Y = typing.Literal[1, 2]
|
type Y = typing.Literal[1, 2]
|
||||||
Z: typing.TypeAlias = dict[int, int]
|
Z: typing.TypeAlias = dict[int, int]
|
||||||
class Foo(dict[str, int]): pass
|
class Foo(dict[str, int]): pass
|
||||||
|
|
||||||
|
# Skip tuples of length one that are single-starred expressions
|
||||||
|
# https://github.com/astral-sh/ruff/issues/16077
|
||||||
|
d[*x]
|
||||||
|
|
|
@ -73,6 +73,12 @@ pub(crate) fn subscript_with_parenthesized_tuple(checker: &Checker, subscript: &
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We should not handle single starred expressions
|
||||||
|
// (regardless of `prefer_parentheses`)
|
||||||
|
if matches!(&tuple_subscript.elts[..], &[Expr::Starred(_)]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Adding parentheses in the presence of a slice leads to a syntax error.
|
// Adding parentheses in the presence of a slice leads to a syntax error.
|
||||||
if prefer_parentheses && tuple_subscript.iter().any(Expr::is_slice_expr) {
|
if prefer_parentheses && tuple_subscript.iter().any(Expr::is_slice_expr) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue