-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
featuretopic-attrstopic-dataclassestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly
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 approveshttps://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
Labels
featuretopic-attrstopic-dataclassestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly