Browse Source

more type fixes

pull/15443/head
svlandeg 3 weeks ago
parent
commit
6a6cc5c7d4
  1. 4
      fastapi/encoders.py
  2. 2
      fastapi/openapi/utils.py
  3. 8
      fastapi/params.py
  4. 4
      fastapi/responses.py

4
fastapi/encoders.py

@ -237,9 +237,9 @@ def jsonable_encoder(
if isinstance(obj, encoder_type):
return encoder_instance(obj)
if include is not None and not isinstance(include, (set, dict)):
include = set(include) # type: ignore[assignment]
include = set(include) # type: ignore[assignment] # ty: ignore[invalid-assignment]
if exclude is not None and not isinstance(exclude, (set, dict)):
exclude = set(exclude) # type: ignore[assignment]
exclude = set(exclude) # type: ignore[assignment] # ty: ignore[invalid-assignment]
if isinstance(obj, BaseModel):
obj_dict = obj.model_dump(
mode="json",

2
fastapi/openapi/utils.py

@ -603,4 +603,4 @@ def get_openapi(
output["tags"] = tags
if external_docs:
output["externalDocs"] = external_docs
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore[no-any-return]

8
fastapi/params.py

@ -23,7 +23,7 @@ class ParamTypes(Enum):
cookie = "cookie"
class Param(FieldInfo): # type: ignore[misc]
class Param(FieldInfo): # type: ignore[misc] # ty: ignore[subclass-of-final-class]
in_: ParamTypes
def __init__(
@ -128,7 +128,7 @@ class Param(FieldInfo): # type: ignore[misc]
use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset}
super().__init__(**use_kwargs)
super().__init__(**use_kwargs) # ty: ignore[invalid-argument-type]
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.default})"
@ -466,7 +466,7 @@ class Cookie(Param): # type: ignore[misc]
)
class Body(FieldInfo): # type: ignore[misc]
class Body(FieldInfo): # type: ignore[misc] # ty: ignore[subclass-of-final-class]
def __init__(
self,
default: Any = Undefined,
@ -572,7 +572,7 @@ class Body(FieldInfo): # type: ignore[misc]
use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset}
super().__init__(**use_kwargs)
super().__init__(**use_kwargs) # ty: ignore[invalid-argument-type]
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.default})"

4
fastapi/responses.py

@ -27,13 +27,13 @@ class _OrjsonModule(Protocol):
try:
ujson = cast(_UjsonModule, importlib.import_module("ujson"))
except ModuleNotFoundError: # pragma: nocover
ujson = None # type: ignore
ujson = None # type: ignore[assignment]
try:
orjson = cast(_OrjsonModule, importlib.import_module("orjson"))
except ModuleNotFoundError: # pragma: nocover
orjson = None # type: ignore
orjson = None # type: ignore[assignment]
@deprecated(

Loading…
Cancel
Save