diff --git a/HISTORY.md b/HISTORY.md index 8a269568..81320cd5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 ` 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. diff --git a/src/cattrs/preconf/orjson.py b/src/cattrs/preconf/orjson.py index 664f92b4..fcd380b9 100644 --- a/src/cattrs/preconf/orjson.py +++ b/src/cattrs/preconf/orjson.py @@ -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 @@ -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):