You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect argument names for dataclass with "private" (mangled) members #19755
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
This is basically #8267 but specifically supporting this for attrs might require more work so I'll keep this open. (e.g. only trimming a single underscore).
[case testNameManglingAttrs]
import attr
@attr.define(kw_only=True)
class X:
a: int
_b: int
__c: int
__d__: int
X(a=1, b=2, X__c=3, d__=4)
X(a=1, b=2, c=3, d__=4) # E: Unexpected keyword argument "c" for "X"
x: X
reveal_type(x.a) # N: Revealed type is "builtins.int"
reveal_type(x._b) # N: Revealed type is "builtins.int"
reveal_type(x._X__c) # N: Revealed type is "builtins.int"
reveal_type(x.__d__) # N: Revealed type is "builtins.int"
[builtins fixtures/list.pyi]
[case testNameManglingDataclasses]
from dataclasses import dataclass
@dataclass(kw_only=True)
class X:
a: int
_b: int
__c: int
__d__: int
X(a=1, _b=2, _X__c=3, __d__=4)
X(a=1, _b=2, __c=3, __d__=4) # E: Unexpected keyword argument "__c" for "X"
x: X
reveal_type(x.a) # N: Revealed type is "builtins.int"
reveal_type(x._b) # N: Revealed type is "builtins.int"
reveal_type(x._X__c) # N: Revealed type is "builtins.int"
reveal_type(x.__d__) # N: Revealed type is "builtins.int"
[builtins fixtures/dataclasses.pyi]
[typing fixtures/typing-medium.pyi]
I will include them as additional test cases. However, the PR has been sleeping for a long time now. A review from someone who has the time to read my lengthy monologue and help fine-tune the different assumptions would be greatly appreciated.
Activity
tmr232 commentedon Aug 29, 2025
There's also a similar issue with
attrs:A5rocks commentedon Aug 30, 2025
This is basically #8267 but specifically supporting this for
attrsmight require more work so I'll keep this open. (e.g. only trimming a single underscore).tyralla commentedon Sep 1, 2025
Both problems would be fixed by merging #16715.
I will include them as additional test cases. However, the PR has been sleeping for a long time now. A review from someone who has the time to read my lengthy monologue and help fine-tune the different assumptions would be greatly appreciated.