Skip to content

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]

@hauntsaninja hauntsaninja merged commit 15b8ca9 into python:master Aug 23, 2025
20 checks passed
@cdce8p cdce8p deleted the match-class-pattern-error branch August 23, 2025 04:32
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.

2 participants