Browse Source

fix type checker

pull/15149/head
svlandeg 4 months ago
parent
commit
e3c13b00f3
  1. 16
      fastapi/responses.py

16
fastapi/responses.py

@ -1,4 +1,5 @@
from typing import Any
import importlib
from typing import Any, Protocol, cast
from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.sse import EventSourceResponse as EventSourceResponse # noqa
@ -17,10 +18,17 @@ except ImportError: # pragma: nocover
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:
import orjson
except ImportError: # pragma: nocover
orjson = None # type: ignore
orjson = cast(_OrjsonModule, importlib.import_module("orjson"))
except ModuleNotFoundError: # pragma: nocover
orjson = None # type: ignore # ty: ignore[unused-ignore-comment]
@deprecated(

Loading…
Cancel
Save