Skip to content

Omit errors for class pattern matches against object #19709

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Aug 21, 2025

Since the class pattern matches any subclass, it can also be used to check whether the matched object has a specific attribute. Mypy should not emit an error for it.

match m:
    case object(foo=_):
        ...

Using object for it is recommended in PEP 635 and more prominently in the precursor PEP 622.

@cdce8p cdce8p added the topic-match-statement Python 3.10's match statement label Aug 21, 2025
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-match-statement Python 3.10's match statement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant