|
|
@ -1,4 +1,5 @@ |
|
|
from typing import Any |
|
|
import importlib |
|
|
|
|
|
from typing import Any, Protocol, cast |
|
|
|
|
|
|
|
|
from fastapi.exceptions import FastAPIDeprecationWarning |
|
|
from fastapi.exceptions import FastAPIDeprecationWarning |
|
|
from fastapi.sse import EventSourceResponse as EventSourceResponse # noqa |
|
|
from fastapi.sse import EventSourceResponse as EventSourceResponse # noqa |
|
|
@ -17,10 +18,17 @@ except ImportError: # pragma: nocover |
|
|
ujson = None # type: ignore |
|
|
ujson = None # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _OrjsonModule(Protocol): |
|
|
|
|
|
OPT_NON_STR_KEYS: int |
|
|
|
|
|
OPT_SERIALIZE_NUMPY: int |
|
|
|
|
|
|
|
|
|
|
|
def dumps(self, __obj: Any, *, option: int = ...) -> bytes: ... |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
import orjson |
|
|
orjson = cast(_OrjsonModule, importlib.import_module("orjson")) |
|
|
except ImportError: # pragma: nocover |
|
|
except ModuleNotFoundError: # pragma: nocover |
|
|
orjson = None # type: ignore |
|
|
orjson = None # type: ignore # ty: ignore[unused-ignore-comment] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@deprecated( |
|
|
@deprecated( |
|
|
|