diff --git a/HISTORY.md b/HISTORY.md index 1e2a36a0..d7292e26 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,10 +1,16 @@ # History +## 23.2.3 (UNRELEASED) + +- Fix a regression when unstructuring dictionary values typed as `Any`. + ([#453](https://github.com/python-attrs/cattrs/issues/453) [#462](https://github.com/python-attrs/cattrs/pull/462)) +- Generate unique files only in case of linecache enabled. + ([#445](https://github.com/python-attrs/cattrs/issues/445) [#441](https://github.com/python-attrs/cattrs/pull/461)) + ## 23.2.2 (2023-11-21) - Fix a regression when unstructuring `Any | None`. - ([#453](https://github.com/python-attrs/cattrs/issues/453)) -- Generate unique files only in case of linecache enabled. ([#445](https://github.com/python-attrs/cattrs/issues/445) [#441](https://github.com/python-attrs/cattrs/pull/461)) + ([#453](https://github.com/python-attrs/cattrs/issues/453) [#454](https://github.com/python-attrs/cattrs/pull/454)) ## 23.2.1 (2023-11-18) diff --git a/src/cattrs/gen/__init__.py b/src/cattrs/gen/__init__.py index cf6dbe39..2b19f064 100644 --- a/src/cattrs/gen/__init__.py +++ b/src/cattrs/gen/__init__.py @@ -743,9 +743,11 @@ def make_mapping_unstructure_fn( if kh == identity: kh = None - val_handler = converter._unstructure_func.dispatch(val_arg) - if val_handler == identity: - val_handler = None + if val_arg is not Any: + # TODO: Remove this once we have more consistent Any handling in place. + val_handler = converter._unstructure_func.dispatch(val_arg) + if val_handler == identity: + val_handler = None globs = { "__cattr_mapping_cl": unstructure_to or cl, diff --git a/tests/test_any.py b/tests/test_any.py new file mode 100644 index 00000000..94fa0bd9 --- /dev/null +++ b/tests/test_any.py @@ -0,0 +1,14 @@ +"""Tests for handling `typing.Any`.""" +from typing import Any, Dict + +from attrs import define + + +@define +class A: + pass + + +def test_unstructuring_dict_of_any(converter): + """Dicts with Any values should use runtime dispatch for their values.""" + assert converter.unstructure({"a": A()}, Dict[str, Any]) == {"a": {}}