File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ def adapted_fields(cl) -> List[Attribute]:
170
170
True ,
171
171
type = type_hints .get (attr .name , attr .type ),
172
172
alias = attr .name ,
173
+ kw_only = attr .kw_only ,
173
174
)
174
175
for attr in attrs
175
176
]
Original file line number Diff line number Diff line change @@ -41,3 +41,19 @@ def test_dataclasses(converter: BaseConverter):
41
41
42
42
assert converter .unstructure (struct ) == unstruct
43
43
assert converter .structure (unstruct , Foo ) == struct
44
+
45
+
46
+ def test_kw_only_propagation (converter : BaseConverter ):
47
+ """KW-only args work.
48
+
49
+ Reproducer from https://github.com/python-attrs/cattrs/issues/637.
50
+ """
51
+
52
+ @dataclasses .dataclass
53
+ class PartialKeywords :
54
+ a1 : str = "Default"
55
+ a2 : str = dataclasses .field (kw_only = True )
56
+
57
+ assert converter .structure ({"a2" : "Value" }, PartialKeywords ) == PartialKeywords (
58
+ a1 = "Default" , a2 = "Value"
59
+ )
You can’t perform that action at this time.
0 commit comments