Skip to content

Commit

Permalink
Broaden loads' type definition for the preconf orjson converter. (#400)
Browse files Browse the repository at this point in the history
`bytes` is not the only input type `orjson.loads` allows.

Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 authored Jul 28, 2023
1 parent 4052f68 commit 3446b50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/cattrs/preconf/orjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)


Expand Down

0 comments on commit 3446b50

Please sign in to comment.