Skip to content

Commit

Permalink
orjson passthrough (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche authored Nov 25, 2023
1 parent 54fcf32 commit dd5b4c4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
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

0 comments on commit dd5b4c4

Please sign in to comment.