mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Reduce duplicate code in json_loads (#106859)
This commit is contained in:
parent
391123beb0
commit
a4f0c84457
@ -39,9 +39,10 @@ def json_loads(__obj: bytes | bytearray | memoryview | str) -> JsonValueType:
|
|||||||
This adds a workaround for orjson not handling subclasses of str,
|
This adds a workaround for orjson not handling subclasses of str,
|
||||||
https://github.com/ijl/orjson/issues/445.
|
https://github.com/ijl/orjson/issues/445.
|
||||||
"""
|
"""
|
||||||
if type(__obj) in (bytes, bytearray, memoryview, str):
|
# Avoid isinstance overhead for the common case
|
||||||
return orjson.loads(__obj) # type:ignore[no-any-return]
|
if type(__obj) not in (bytes, bytearray, memoryview, str) and isinstance(
|
||||||
if isinstance(__obj, str):
|
__obj, str
|
||||||
|
):
|
||||||
return orjson.loads(str(__obj)) # type:ignore[no-any-return]
|
return orjson.loads(str(__obj)) # type:ignore[no-any-return]
|
||||||
return orjson.loads(__obj) # type:ignore[no-any-return]
|
return orjson.loads(__obj) # type:ignore[no-any-return]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user