Skip to content

Allow Any to match sequence patterns in match/case#18448

Merged
hauntsaninja merged 2 commits into
python:masterfrom
sterliakov:bugfix/st-match-case-any-sequence
Jan 13, 2025
Merged

Allow Any to match sequence patterns in match/case#18448
hauntsaninja merged 2 commits into
python:masterfrom
sterliakov:bugfix/st-match-case-any-sequence

Conversation

@sterliakov

@sterliakov sterliakov commented Jan 11, 2025

Copy link
Copy Markdown
Collaborator

Fixes #17095 (comment, the primary issue was already fixed somewhere before). Fixes #16272. Fixes #12532. Fixes #12770.

Prior to this PR mypy did not consider that Any can match any patterns, including sequence patterns (e.g. case [_]). This PR allows matching Any against any such patterns.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

jax (https://github.com/google/jax)
+ jax/_src/pallas/mosaic_gpu/primitives.py:505: error: Incompatible types in capture pattern (pattern captures type "int", variable has type "object")  [misc]

@sterliakov sterliakov marked this pull request as ready for review January 12, 2025 01:00
@sterliakov

Copy link
Copy Markdown
Collaborator Author

Primer diff is fine - that branch used to be erroneously considered unreachable. Now we're fine, lhs_swizzle has to be explicitly annotated (we don't attempt such inference with match, at least now).

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants