Skip to content

[ty] Visit pattern arguments in source order#23398

Merged
charliermarsh merged 1 commit intomainfrom
charlie/pattern-source
Feb 18, 2026
Merged

[ty] Visit pattern arguments in source order#23398
charliermarsh merged 1 commit intomainfrom
charlie/pattern-source

Conversation

@charliermarsh
Copy link
Member

Summary

PatternArguments::visit_source_order() visited all positional patterns first, then all keyword patterns. But keyword patterns can appear before positional patterns in the source text:

case ast.Attribute(value=ast.Name(id), attr)

The visitor would process attr first, then value=ast.Name(id).

We now visit in source order using the pattern established via arguments_source_order.

Closes astral-sh/ty#2417.

@charliermarsh charliermarsh added bug Something isn't working ty Multi-file analysis & type inference labels Feb 18, 2026
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Nice, I suspected the bug was something like this. LGTM!

@AlexWaygood AlexWaygood added the server Related to the LSP server label Feb 18, 2026
@AlexWaygood
Copy link
Member

I bet there are probably other invalid-syntax scenarios where we make this mistake (but finding those doesn't need to block merging this, obviously)

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 18, 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.

@charliermarsh charliermarsh merged commit c4c1f54 into main Feb 18, 2026
47 checks passed
@charliermarsh charliermarsh deleted the charlie/pattern-source branch February 18, 2026 18:52
charliermarsh added a commit that referenced this pull request Feb 18, 2026
## Summary

Like #23398, but for `case {**rest, 'key': value}`. The code previously
assumed that `**rest` always came last.

---------

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic-tokens panic while typing out a match/case statement

2 participants