Skip to content

Allow match identifiers after a semicolon - #29760

Merged
charliermarsh merged 4 commits into
mainfrom
fix/semicolon-match-names
Oct 28, 2026
Merged

charliermarsh merged 4 commits into
mainfrom
fix/semicolon-match-names

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

match is a soft keyword. It can name a variable, a function, or the target of an annotated assignment, including after a semicolon.

first(); match = value
first(); match(value)
first(); match[0]: int

The parser reported a compound-statement error as soon as it saw the match token. We now check the preceding separator when parsing a match statement. If the token turns out to be an identifier, speculative parsing discards the diagnostic. A genuine match statement on the same logical line still produces the original error.

@charliermarsh charliermarsh added bug An issue describing something that isn't working, or a PR that fixes a bug parser Related to the parser labels Oct 27, 2026
@charliermarsh charliermarsh added bug An issue describing something that isn't working, or a PR that fixes a bug parser Related to the parser labels Oct 27, 2026
@astral-automations-bot

astral-automations-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Memory usage report

Memory usage unchanged βœ…


Results for 565a712 Β· Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

ecosystem-analyzer results

No diagnostic changes detected βœ…

Full report with detailed diff Β· Timing results


Results for 565a712 Β· Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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.


Results for 565a712 Β· Workflow run

@codspeed

codspeed Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

βœ… 274 untouched benchmarks
⏩ 14 skipped benchmarks1


Comparing fix/semicolon-match-names (565a712) with main (4549e31)

Open in CodSpeed

Footnotes

  1. 14 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread crates/ruff_python_parser/src/lexer.rs Outdated
Comment on lines +48 to +50
/// The kind of the previous non-trivia token.
previous_kind: Option<TokenKind>,

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 don't think we should track this in the Lexer. It results in a write on the hot lex_token path, without being needed in most cases.

@charliermarsh
charliermarsh merged commit 48630fb into main Oct 28, 2026
79 checks passed
@charliermarsh
charliermarsh deleted the fix/semicolon-match-names branch October 28, 2026 00:10

This branch was previously deployed

1 inactive deployment
automations β€” 565a7129 Deployed Oct 27, 2026 by charliermarsh via security-review / security review #95974
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug parser Related to the parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants