From 3446b50e071355dbfc604bc91fdc79d7eb0f660f Mon Sep 17 00:00:00 2001 From: Zixuan Li <39874143+PIG208@users.noreply.github.com> Date: Fri, 28 Jul 2023 11:41:33 -0400 Subject: [PATCH] Broaden loads' type definition for the preconf orjson converter. (#400) `bytes` is not the only input type `orjson.loads` allows. Signed-off-by: Zixuan James Li --- HISTORY.md | 2 ++ src/cattrs/preconf/orjson.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a7ef5106..c62f0885 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -24,6 +24,8 @@ ([#388](https://github.com/python-attrs/cattrs/pull/388)) - Fix copying of converters using function hooks. ([#398](https://github.com/python-attrs/cattrs/issues/398) [#399](https://github.com/python-attrs/cattrs/pull/399)) +- Broaden loads' type definition for the preconf orjson converter. + ([#400](https://github.com/python-attrs/cattrs/pull/400)) ## 23.1.2 (2023-06-02) diff --git a/src/cattrs/preconf/orjson.py b/src/cattrs/preconf/orjson.py index 6f357230..297a79fb 100644 --- a/src/cattrs/preconf/orjson.py +++ b/src/cattrs/preconf/orjson.py @@ -2,7 +2,7 @@ from base64 import b85decode, b85encode from datetime import datetime from enum import Enum -from typing import Any, Type, TypeVar +from typing import Any, Type, TypeVar, Union from orjson import dumps, loads @@ -17,7 +17,7 @@ class OrjsonConverter(Converter): def dumps(self, obj: Any, unstructure_as: Any = None, **kwargs: Any) -> bytes: return dumps(self.unstructure(obj, unstructure_as=unstructure_as), **kwargs) - def loads(self, data: bytes, cl: Type[T]) -> T: + def loads(self, data: Union[bytes, bytearray, memoryview, str], cl: Type[T]) -> T: return self.structure(loads(data), cl)