Skip to content

mypy generates __match_args__ for dataclasses and NamedTuples on Python <3.10 #12489

Closed
@AlexWaygood

Description

@AlexWaygood

Bug Report

Not a big deal, but mypy appears to generate __match_args__ for dataclasses and NamedTuples even when running with --python-version set to 3.9:

from dataclasses import dataclass
from typing import NamedTuple

@dataclass
class One:
    bar: int

f: One
reveal_type(f.__match_args__)  # Revealed type is "Tuple[Literal['bar']]"

class Two(NamedTuple):
    baz: str

g: Two
reveal_type(g.__match_args__)  # Revealed type is "Tuple[Literal['baz']]"

Expected Behavior

Mypy should not autogenerate __match_args__ when running with --python-version set to <3.10, as pattern-matching is new in 3.10.

Your Environment

  • Mypy version used: 0.950+dev.a33d2353a81d075850a487f3913720037f2473aa (compiled: no)
  • Mypy command-line flags: --python-version 3.9
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10
  • Operating system and version: Windows

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions