Skip to content

Commit dd5b4c4

Browse files
authored
orjson passthrough (#463)
1 parent 54fcf32 commit dd5b4c4

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Add support for [PEP 695](https://peps.python.org/pep-0695/) type aliases.
66
([#452](https://github.com/python-attrs/cattrs/pull/452))
7+
- The {class}`orjson preconf converter <cattrs.preconf.orjson.OrjsonConverter>` now passes through dates and datetimes to orjson while unstructuring, greatly improving speed.
78
- More robust support for `Annotated` and `NotRequired` in TypedDicts.
89
([#450](https://github.com/python-attrs/cattrs/pull/450))
910
- [PEP 695](https://peps.python.org/pep-0695/) generics are now tested.

src/cattrs/preconf/orjson.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def configure_converter(converter: BaseConverter):
2828
Configure the converter for use with the orjson library.
2929
3030
* bytes are serialized as base85 strings
31-
* datetimes are serialized as ISO 8601
31+
* datetimes and dates are passed through to be serialized as RFC 3339 by orjson
3232
* sets are serialized as lists
3333
* string enum mapping keys have special handling
3434
* mapping keys are coerced into strings when unstructuring
@@ -38,9 +38,7 @@ def configure_converter(converter: BaseConverter):
3838
)
3939
converter.register_structure_hook(bytes, lambda v, _: b85decode(v))
4040

41-
converter.register_unstructure_hook(datetime, lambda v: v.isoformat())
4241
converter.register_structure_hook(datetime, lambda v, _: datetime.fromisoformat(v))
43-
converter.register_unstructure_hook(date, lambda v: v.isoformat())
4442
converter.register_structure_hook(date, lambda v, _: date.fromisoformat(v))
4543

4644
def gen_unstructure_mapping(cl: Any, unstructure_to=None):

0 commit comments

Comments
 (0)