Skip to content

Commit 3446b50

Browse files
authored
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 <p359101898@gmail.com>
1 parent 4052f68 commit 3446b50

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
([#388](https://github.com/python-attrs/cattrs/pull/388))
2525
- Fix copying of converters using function hooks.
2626
([#398](https://github.com/python-attrs/cattrs/issues/398) [#399](https://github.com/python-attrs/cattrs/pull/399))
27+
- Broaden loads' type definition for the preconf orjson converter.
28+
([#400](https://github.com/python-attrs/cattrs/pull/400))
2729

2830
## 23.1.2 (2023-06-02)
2931

src/cattrs/preconf/orjson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from base64 import b85decode, b85encode
33
from datetime import datetime
44
from enum import Enum
5-
from typing import Any, Type, TypeVar
5+
from typing import Any, Type, TypeVar, Union
66

77
from orjson import dumps, loads
88

@@ -17,7 +17,7 @@ class OrjsonConverter(Converter):
1717
def dumps(self, obj: Any, unstructure_as: Any = None, **kwargs: Any) -> bytes:
1818
return dumps(self.unstructure(obj, unstructure_as=unstructure_as), **kwargs)
1919

20-
def loads(self, data: bytes, cl: Type[T]) -> T:
20+
def loads(self, data: Union[bytes, bytearray, memoryview, str], cl: Type[T]) -> T:
2121
return self.structure(loads(data), cl)
2222

2323

0 commit comments

Comments
 (0)