Skip to content

__match_args__ variable type differes when generating stubs for keyword only dataclasses #18863

Closed
@dstansby

Description

@dstansby

Bug Report

Generating and then testing stubs on a dataclass with frozen keyword arguments fails.

To Reproduce

import dataclasses

@dataclasses.dataclass(kw_only=True)
class A:
    a: int

Then generate a stub, and run stubtest. The generated stub is (indentical to the above):

import dataclasses

@dataclasses.dataclass(kw_only=True)
class A:
    a: int

Expected Behavior
stubtest passes

Actual Behavior

% python -m mypy.stubtest test
error: test.A.__match_args__ variable differs from runtime type tuple[()]
Stub: in file /Users/dstansby/software/mpl/matplotlib/test.pyi:-1
tuple[Literal['a']]
Runtime:
()

Found 1 error (checked 1 module)

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: Python 3.12.9

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions