Skip to content

Commit

Permalink
Fix unstructure_to
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Oct 6, 2024
1 parent 85850c7 commit a95d5ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cattrs/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def mapping_unstructure_factory(

lines = [f"def {fn_name}(mapping):"]

if unstructure_to is dict or origin is dict:
if unstructure_to is dict or unstructure_to is None and origin is dict:
if kh is None and val_handler is None:
# Simplest path.
return dict
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ def test_mapping_unstructure_direct(genconverter: Converter):

if is_py310_plus:
assert genconverter.get_unstructure_hook(dict[str, int]) is dict


def test_mapping_unstructure_to(genconverter: Converter):
"""`unstructure_to` works."""
hook = mapping_unstructure_factory(Dict[str, str], genconverter, unstructure_to=Map)
assert hook({"a": "a"}).__class__ is Map

0 comments on commit a95d5ff

Please sign in to comment.