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
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add support for [PEP 695](https://peps.python.org/pep-0695/) type aliases.
([#452](https://github.com/python-attrs/cattrs/pull/452))
- The {class}`orjson preconf converter <cattrs.preconf.orjson.OrjsonConverter>` now passes through dates and datetimes to orjson while unstructuring, greatly improving speed.
- More robust support for `Annotated` and `NotRequired` in TypedDicts.
([#450](https://github.com/python-attrs/cattrs/pull/450))
- [PEP 695](https://peps.python.org/pep-0695/) generics are now tested.
Expand Down
4 changes: 1 addition & 3 deletions src/cattrs/preconf/orjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def configure_converter(converter: BaseConverter):
Configure the converter for use with the orjson library.

* bytes are serialized as base85 strings
* datetimes are serialized as ISO 8601
* datetimes and dates are passed through to be serialized as RFC 3339 by orjson
* sets are serialized as lists
* string enum mapping keys have special handling
* mapping keys are coerced into strings when unstructuring
Expand All @@ -38,9 +38,7 @@ def configure_converter(converter: BaseConverter):
)
converter.register_structure_hook(bytes, lambda v, _: b85decode(v))

converter.register_unstructure_hook(datetime, lambda v: v.isoformat())
converter.register_structure_hook(datetime, lambda v, _: datetime.fromisoformat(v))
converter.register_unstructure_hook(date, lambda v: v.isoformat())
converter.register_structure_hook(date, lambda v, _: date.fromisoformat(v))

def gen_unstructure_mapping(cl: Any, unstructure_to=None):
Expand Down