Incorrect argument names for dataclass with "private" (mangled) members
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in main.py and run mypy 1.17.1 against Python 3.13, comparing the accepted keyword names with runtime dataclass behavior. Trace the dataclass argument inference used for the private member and verify that _Data__mangled is accepted while __mangled is rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100