Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Our backwards-compatibility policy can be found [here](https://github.com/python

- Fix an `AttributeError` in `cattrs` internals that could be triggered by using the `include_subclasses` strategy in a `structure_hook_factory`
([#721](https://github.com/python-attrs/cattrs/issues/721), [#722](https://github.com/python-attrs/cattrs/pull/722))
- Fix the `detailed_validation` parameter being passed under the wrong name in {func}`namedtuple_dict_structure_factory <cattrs.cols.namedtuple_dict_structure_factory>`, causing it to be silently ignored.
([#723](https://github.com/python-attrs/cattrs/pull/723))

## 26.1.0 (2026-02-18)

Expand Down
2 changes: 1 addition & 1 deletion src/cattrs/cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def namedtuple_dict_structure_factory(
cl,
converter,
_cattrs_forbid_extra_keys=forbid_extra_keys,
_cattrs_use_detailed_validation=detailed_validation,
_cattrs_detailed_validation=detailed_validation,
_cattrs_use_linecache=use_linecache,
**kwargs,
)
Expand Down
27 changes: 26 additions & 1 deletion tests/test_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namedtuple_dict_unstructure_factory,
)
from cattrs.converters import Converter
from cattrs.errors import ForbiddenExtraKeysError
from cattrs.errors import ClassValidationError, ForbiddenExtraKeysError


def test_simple_hetero_tuples(genconverter: Converter):
Expand Down Expand Up @@ -141,3 +141,28 @@ class Test(NamedTuple):

assert isinstance(exc, ForbiddenExtraKeysError)
assert exc.extra_fields == {"b"}


def test_dict_namedtuples_detailed_validation():
"""Passing detailed_validation to namedtuple_dict_structure_factory works.

Regression test for the parameter being passed under the wrong name.
"""

class Test(NamedTuple):
a: int

# Create a converter that does NOT use detailed validation by default.
c = Converter(detailed_validation=False)

# But explicitly enable it in the factory.
c.register_structure_hook_factory(
lambda t: t is Test,
lambda t, conv: namedtuple_dict_structure_factory(t, conv, True),
)

# With detailed validation, structuring errors should be wrapped
# in a ClassValidationError instead of being raised directly.

with raises(ClassValidationError):
c.structure({"a": "not_an_int"}, Test)