Skip to content

Disallow starred expressions as values of starred expressions#24280

Merged
dylwil3 merged 3 commits intoastral-sh:mainfrom
dylwil3:starred-expr-syntax
Apr 2, 2026
Merged

Disallow starred expressions as values of starred expressions#24280
dylwil3 merged 3 commits intoastral-sh:mainfrom
dylwil3:starred-expr-syntax

Conversation

@dylwil3
Copy link
Copy Markdown
Collaborator

@dylwil3 dylwil3 commented Mar 29, 2026

Part of #19077

@dylwil3 dylwil3 added bug Something isn't working parser Related to the parser labels Mar 29, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 29, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@dylwil3 dylwil3 marked this pull request as ready for review April 2, 2026 12:44
Comment on lines 2547 to 2555
let parsed_expr = match context.starred_expression_precedence() {
StarredExpressionPrecedence::Conditional => {
self.parse_conditional_expression_or_higher_impl(context)
}
StarredExpressionPrecedence::Conditional => self
.parse_conditional_expression_or_higher_impl(
// test_err starred_starred_expression
// print(*
// *[])
context.disallow_starred_expressions(),
),
StarredExpressionPrecedence::BitwiseOr => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought this might not be the correct place but then I realize that this is actually correct given that if we're parsing an expression followed by the * token, then that expression cannot itself be a starred expression unless it's a keyword-variadic argument which is actually a different token (**).

I think we should add this example as well:

print(* *[])

For posterity, I thought the issue must be in parse_arguments instead. The lexer emits [..., Star, Star, ...] for the above code and [..., Star, NonLogicalNewline, Star, ...] for the one in the test. So, I thought we'd need to special case this order of two consecutive Star tokens that could contain a NonLogicalNewline token in between and check whether they're actually consecutive or not.

@dylwil3 dylwil3 enabled auto-merge (squash) April 2, 2026 14:52
@dylwil3 dylwil3 merged commit 5f88756 into astral-sh:main Apr 2, 2026
47 checks passed
carljm added a commit that referenced this pull request Apr 2, 2026
* main:
  Add a "release-gate" step to the release workflow (#24365)
  Disallow starred expressions as values of starred expressions (#24280)
  [`pyupgrade`] Ignore strings with string-only escapes (`UP012`) (#16058)
  [ty] Improve consistency and quality of diagnostics relating to invalid type forms (#24325)
  [flake8-type-checking] Clarify import cycle wording for TC001/TC002/TC003 (#24322)
  [`flake8-errmsg`] Avoid shadowing existing `msg` in fix for `EM101` (#24363)
  `RUF072`: skip formfeeds on dedent (#24308)
  Replace unmaintained `unic-ucd-category` crate with `icu_properties` (#24344)
  [ty] Replace markdown hard line breaks in snapshot tests (#24361)
  [ty] Move snapshot for code action test with trailing whitespace to external file (#24359)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser Related to the parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants