Skip to content

Can't determine input argument type with structural pattern matching when class is set as attribute of another class #13455

Closed
@jeremyn

Description

@jeremyn

Bug Report

mypy errors with "Cannot determine type" of an input argument when using structural pattern matching against a class set as an attribute of another class.

To Reproduce

Example:

from dataclasses import dataclass

@dataclass
class A:
    x: str

class B:
    A = A

match A("y"):
    case B.A(z):
        # mypy: error: Cannot determine type of "z"
        # correctly prints: "x: y"
        print(f"x: {z}")

case A works fine, as does defining A directly inside B instead of setting A = A.

Expected Behavior

I don't get the mypy error above.

Actual Behavior

I get the error.

Your Environment

Mypy version used: 0.971 (compiled: yes)
Python version used: 3.10.4
Operating system and version: Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-aliasTypeAlias and other type alias issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions