Skip to content

Commit

Permalink
Expose mapping_unstructure_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Oct 5, 2024
1 parent ae80674 commit c2b8e4b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
([#577](https://github.com/python-attrs/cattrs/pull/577))
- Add a [Migrations](https://catt.rs/latest/migrations.html) page, with instructions on migrating changed behavior for each version.
([#577](https://github.com/python-attrs/cattrs/pull/577))
- Expose {func}`cattrs.cols.mapping_unstructure_factory` through {mod}`cattrs.cols`.
- Python 3.13 is now supported.
([#543](https://github.com/python-attrs/cattrs/pull/543) [#547](https://github.com/python-attrs/cattrs/issues/547))

Expand All @@ -39,7 +40,7 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
([#473](https://github.com/python-attrs/cattrs/pull/473))
- **Minor change**: Heterogeneous tuples are now unstructured into tuples instead of lists by default; this is significantly faster and widely supported by serialization libraries.
([#486](https://github.com/python-attrs/cattrs/pull/486))
- **Minor change**: {py:func}`cattrs.gen.make_dict_structure_fn` will use the value for the `prefer_attrib_converters` parameter from the given converter by default now.
- **Minor change**: {func}`cattrs.gen.make_dict_structure_fn` will use the value for the `prefer_attrib_converters` parameter from the given converter by default now.
If you're using this function directly, the old behavior can be restored by passing in the desired values explicitly.
([#527](https://github.com/python-attrs/cattrs/issues/527) [#528](https://github.com/python-attrs/cattrs/pull/528))
- Introduce {meth}`BaseConverter.get_structure_hook` and {meth}`BaseConverter.get_unstructure_hook` methods.
Expand Down
1 change: 1 addition & 0 deletions docs/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Available hook factories are:
* {meth}`namedtuple_dict_structure_factory <cattrs.cols.namedtuple_dict_structure_factory>`
* {meth}`namedtuple_dict_unstructure_factory <cattrs.cols.namedtuple_dict_unstructure_factory>`
* {meth}`mapping_structure_factory <cattrs.cols.mapping_structure_factory>`
* {meth}`mapping_unstructure_factory <cattrs.cols.mapping_unstructure_factory>`

Additional predicates and hook factories will be added as requested.

Expand Down
2 changes: 2 additions & 0 deletions src/cattrs/cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
make_dict_unstructure_fn_from_attrs,
make_hetero_tuple_unstructure_fn,
mapping_structure_factory,
mapping_unstructure_factory,
)
from .gen import make_iterable_unstructure_fn as iterable_unstructure_factory

Expand All @@ -48,6 +49,7 @@
"namedtuple_dict_structure_factory",
"namedtuple_dict_unstructure_factory",
"mapping_structure_factory",
"mapping_unstructure_factory",
]


Expand Down
5 changes: 4 additions & 1 deletion src/cattrs/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ def make_hetero_tuple_unstructure_fn(
MappingUnstructureFn = Callable[[Mapping[Any, Any]], Any]


def make_mapping_unstructure_fn(
# This factory is here for backwards compatibility and circular imports.
def mapping_unstructure_factory(
cl: Any,
converter: BaseConverter,
unstructure_to: Any = None,
Expand Down Expand Up @@ -896,6 +897,8 @@ def make_mapping_unstructure_fn(
return globs[fn_name]


make_mapping_unstructure_fn: Final = mapping_unstructure_factory

MappingStructureFn = Callable[[Mapping[Any, Any], Any], T]


Expand Down

0 comments on commit c2b8e4b

Please sign in to comment.