diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF031.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF031.py index e784125680..9e869b22db 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF031.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF031.py @@ -42,3 +42,7 @@ import typing type Y = typing.Literal[1, 2] Z: typing.TypeAlias = dict[int, int] 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] diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF031_prefer_parens.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF031_prefer_parens.py index 0d9afff348..3c4231c140 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF031_prefer_parens.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF031_prefer_parens.py @@ -42,3 +42,7 @@ import typing type Y = typing.Literal[1, 2] Z: typing.TypeAlias = dict[int, int] 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] diff --git a/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs b/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs index 0242c1717f..9764a8155c 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/incorrectly_parenthesized_tuple_in_subscript.rs @@ -73,6 +73,12 @@ pub(crate) fn subscript_with_parenthesized_tuple(checker: &Checker, subscript: & 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. if prefer_parentheses && tuple_subscript.iter().any(Expr::is_slice_expr) { return;