Skip to content

Commit d8f17b7

Browse files
committed
Merge branch '24.1'
2 parents a8d3e44 + ec53833 commit d8f17b7

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

HISTORY.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# History
2+
23
```{currentmodule} cattrs
4+
35
```
46

57
This project adheres to [Calendar Versioning](https://calver.org/).
@@ -9,7 +11,6 @@ The third number is for emergencies when we need to start branches for older rel
911

1012
Our backwards-compatibility policy can be found [here](https://github.com/python-attrs/cattrs/blob/main/.github/SECURITY.md).
1113

12-
1314
## 25.1.0 (UNRELEASED)
1415

1516
- **Potentially breaking**: The converters raise {class}`StructureHandlerNotFoundError` more eagerly (on hook creation, instead of on hook use).
@@ -47,6 +48,11 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
4748
([#594](https://github.com/python-attrs/cattrs/pull/594)).
4849
- Adopt the Contributor Covenant Code of Conduct (just like _attrs_).
4950

51+
## 24.1.3 (2025-03-25)
52+
53+
- Fix structuring of keyword-only dataclass fields when not using detailed validation.
54+
([#637](https://github.com/python-attrs/cattrs/issues/637) [#638](https://github.com/python-attrs/cattrs/pull/638))
55+
5056
## 24.1.2 (2024-09-22)
5157

5258
- Fix {meth}`BaseConverter.register_structure_hook` and {meth}`BaseConverter.register_unstructure_hook` type hints.

src/cattrs/_compat.py

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def adapted_fields(cl: type) -> list[Attribute]:
164164
True,
165165
type=type_hints.get(attr.name, attr.type),
166166
alias=attr.name,
167+
kw_only=getattr(attr, "kw_only", False),
167168
)
168169
for attr in attrs
169170
]

tests/test_dataclasses.py

+20
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
from typing import List
33

44
import attr
5+
import pytest
56

67
from cattrs import BaseConverter
78

9+
from ._compat import is_py310_plus
10+
811

912
@dataclasses.dataclass
1013
class Foo:
@@ -41,3 +44,20 @@ def test_dataclasses(converter: BaseConverter):
4144

4245
assert converter.unstructure(struct) == unstruct
4346
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+
)

0 commit comments

Comments
 (0)