Skip to content

Commit 2aafe76

Browse files
committed
add test cases for attrs and dataclasses
1 parent 4eb8996 commit 2aafe76

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test-data/unit/check-mangling.test

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,46 @@ a = {"_A__a": 1} # E: Missing key "__a" for TypedDict "A" \
346346
# E: Extra key "_A__a" for TypedDict "A"
347347

348348
[typing fixtures/typing-typeddict.pyi]
349+
350+
[case testNameManglingAttrs]
351+
import attr
352+
353+
@attr.define(kw_only=True)
354+
class X:
355+
a: int
356+
_b: int
357+
__c: int
358+
__d__: int
359+
360+
X(a=1, b=2, X__c=3, d__=4)
361+
X(a=1, b=2, c=3, d__=4) # E: Unexpected keyword argument "c" for "X"
362+
363+
x: X
364+
reveal_type(x.a) # N: Revealed type is "builtins.int"
365+
reveal_type(x._b) # N: Revealed type is "builtins.int"
366+
reveal_type(x._X__c) # N: Revealed type is "builtins.int"
367+
reveal_type(x.__d__) # N: Revealed type is "builtins.int"
368+
369+
[builtins fixtures/list.pyi]
370+
371+
[case testNameManglingDataclasses]
372+
from dataclasses import dataclass
373+
374+
@dataclass(kw_only=True)
375+
class X:
376+
a: int
377+
_b: int
378+
__c: int
379+
__d__: int
380+
381+
X(a=1, _b=2, _X__c=3, __d__=4)
382+
X(a=1, _b=2, __c=3, __d__=4) # E: Unexpected keyword argument "__c" for "X"
383+
384+
x: X
385+
reveal_type(x.a) # N: Revealed type is "builtins.int"
386+
reveal_type(x._b) # N: Revealed type is "builtins.int"
387+
reveal_type(x._X__c) # N: Revealed type is "builtins.int"
388+
reveal_type(x.__d__) # N: Revealed type is "builtins.int"
389+
390+
[builtins fixtures/dataclasses.pyi]
391+
[typing fixtures/typing-medium.pyi]

0 commit comments

Comments
 (0)