Skip to content

Incorrect argument names for dataclass with "private" (mangled) members #19755

@tmr232

Description

@tmr232

Bug Report

Mypy infers dataclass arguments incorrectly when a class has private (__name) members.

To Reproduce

from dataclasses import dataclass


@dataclass(kw_only=True)
class Data:
    __mangled: int


Data(_Data__mangled=1)  # Runs correctly, but mypy complains
Data(__mangled=1)       # Fails, but mypy approves

https://mypy-play.net/?mypy=latest&python=3.13&gist=f585904f6f5652ee86cd11d6502de13f

Expected Behavior

I expect mypy's behaviour to match the execution and requrie the _Data__mangled argument.
Additionally, I expect it to reject the __mangled argument name as unexpected.

Actual Behavior

main.py:9: error: Unexpected keyword argument "_Data__mangled" for "Data"; did you mean "__mangled"? [call-arg]
Found 1 error in 1 file (checked 1 source file)

Your Environment

I reproduced this on mypy-play.net with Python 3.13

  • Mypy version used: 1.17.1
  • Mypy command-line flags: default mypy-play.net settings
  • Python version used: Python 3.13

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions