File tree 3 files changed +28
-0
lines changed
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1
1
# History
2
+
2
3
``` {currentmodule} cattrs
4
+
3
5
```
4
6
5
7
This project adheres to [ Calendar Versioning] ( https://calver.org/ ) .
@@ -9,6 +11,11 @@ The third number is for emergencies when we need to start branches for older rel
9
11
10
12
Our backwards-compatibility policy can be found [ here] ( https://github.com/python-attrs/cattrs/blob/main/.github/SECURITY.md ) .
11
13
14
+ ## 24.1.3 (UNRELEASED)
15
+
16
+ - Fix structuring of keyword-only dataclass fields when not using detailed validation.
17
+ ([ #637 ] ( https://github.com/python-attrs/cattrs/issues/637 ) [ #638 ] ( https://github.com/python-attrs/cattrs/pull/638 ) )
18
+
12
19
## 24.1.2 (2024-09-22)
13
20
14
21
- Fix {meth}` BaseConverter.register_structure_hook ` and {meth}` BaseConverter.register_unstructure_hook ` type hints.
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 = getattr (attr , "kw_only" , False ),
173
174
)
174
175
for attr in attrs
175
176
]
Original file line number Diff line number Diff line change 2
2
from typing import List
3
3
4
4
import attr
5
+ import pytest
5
6
6
7
from cattrs import BaseConverter
7
8
9
+ from ._compat import is_py310_plus
10
+
8
11
9
12
@dataclasses .dataclass
10
13
class Foo :
@@ -41,3 +44,20 @@ def test_dataclasses(converter: BaseConverter):
41
44
42
45
assert converter .unstructure (struct ) == unstruct
43
46
assert converter .structure (unstruct , Foo ) == struct
47
+
48
+
49
+ @pytest .mark .skipif (not is_py310_plus , reason = "kwonly fields are Python 3.10+" )
50
+ def test_kw_only_propagation (converter : BaseConverter ):
51
+ """KW-only args work.
52
+
53
+ Reproducer from https://github.com/python-attrs/cattrs/issues/637.
54
+ """
55
+
56
+ @dataclasses .dataclass
57
+ class PartialKeywords :
58
+ a1 : str = "Default"
59
+ a2 : str = dataclasses .field (kw_only = True )
60
+
61
+ assert converter .structure ({"a2" : "Value" }, PartialKeywords ) == PartialKeywords (
62
+ a1 = "Default" , a2 = "Value"
63
+ )
You can’t perform that action at this time.
0 commit comments