Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Jan 11, 2025

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.

Copy link
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
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).

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@hauntsaninja hauntsaninja merged commit ee364ce into python:master Jan 13, 2025
18 checks passed
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