Skip to content

Remove unnecessary error message for match class patterns #19708

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

Remove Cannot determine type of ... error for class patterns if the class to match cannot be resolved. In these cases a Name ... is not defined error is already emitted. The captured variable should simply be inferred as Any.

Previously, this was especially an issue for class matches to a class from an untyped library together with a MemberExpr. An example from pylint / astroid which shouldn't emit any errors:

from typing import Any
from astroid import nodes

def func(var: Any) -> None:
    match var:
        case nodes.Assign(targets=t):
            reveal_type(t)  # Any

@cdce8p cdce8p added the topic-match-statement Python 3.10's match statement label Aug 21, 2025
@cdce8p cdce8p force-pushed the match-class-pattern-error branch from 1026b0e to a9aa418 Compare August 21, 2025 18:34
Copy link
Contributor

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

core (https://github.com/home-assistant/core)
- homeassistant/components/onkyo/media_player.py:354: error: Cannot determine type of "volume"  [has-type]
- homeassistant/components/onkyo/media_player.py:360: error: Cannot determine type of "muting"  [has-type]
- homeassistant/components/onkyo/media_player.py:363: error: Cannot determine type of "source"  [has-type]
- homeassistant/components/onkyo/media_player.py:364: error: Cannot determine type of "source"  [has-type]
- homeassistant/components/onkyo/media_player.py:366: error: Cannot determine type of "source"  [has-type]
- homeassistant/components/onkyo/media_player.py:383: error: Cannot determine type of "sound_mode"  [has-type]
- homeassistant/components/onkyo/media_player.py:384: error: Cannot determine type of "sound_mode"  [has-type]
- homeassistant/components/onkyo/media_player.py:386: error: Cannot determine type of "sound_mode"  [has-type]
- homeassistant/components/onkyo/media_player.py:398: error: Cannot determine type of "hdmi_output"  [has-type]
- homeassistant/components/onkyo/media_player.py:403: error: Cannot determine type of "preset"  [has-type]

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