diff --git a/fastapi/encoders.py b/fastapi/encoders.py index 451ea0760..c416abbcb 100644 --- a/fastapi/encoders.py +++ b/fastapi/encoders.py @@ -240,7 +240,7 @@ def jsonable_encoder( custom_encoder=encoders, sqlalchemy_safe=sqlalchemy_safe, ) - if dataclasses.is_dataclass(obj): + if dataclasses.is_dataclass(type(obj)): obj_dict = dataclasses.asdict(obj) return jsonable_encoder( obj_dict, diff --git a/fastapi/routing.py b/fastapi/routing.py index 54c75a027..40c66f2f2 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -119,7 +119,7 @@ def _prepare_response_content( ) for k, v in res.items() } - elif dataclasses.is_dataclass(res): + elif dataclasses.is_dataclass(type(res)): return dataclasses.asdict(res) return res diff --git a/fastapi/security/api_key.py b/fastapi/security/api_key.py index 70c2dca8a..6d6dd01d9 100644 --- a/fastapi/security/api_key.py +++ b/fastapi/security/api_key.py @@ -100,7 +100,7 @@ class APIKeyQuery(APIKeyBase): ] = True, ): self.model: APIKey = APIKey( - **{"in": APIKeyIn.query}, # type: ignore[arg-type] + **{"in": APIKeyIn.query}, name=name, description=description, ) @@ -188,7 +188,7 @@ class APIKeyHeader(APIKeyBase): ] = True, ): self.model: APIKey = APIKey( - **{"in": APIKeyIn.header}, # type: ignore[arg-type] + **{"in": APIKeyIn.header}, name=name, description=description, ) @@ -276,7 +276,7 @@ class APIKeyCookie(APIKeyBase): ] = True, ): self.model: APIKey = APIKey( - **{"in": APIKeyIn.cookie}, # type: ignore[arg-type] + **{"in": APIKeyIn.cookie}, name=name, description=description, ) diff --git a/pyproject.toml b/pyproject.toml index 7709451ff..bf0e10a8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -142,6 +142,7 @@ source-includes = [ name = "fastapi-slim" [tool.mypy] +plugins = ["pydantic.mypy"] strict = true [[tool.mypy.overrides]] diff --git a/requirements-tests.txt b/requirements-tests.txt index b9f2b2b66..cbe5599b9 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -2,7 +2,7 @@ -r requirements-docs-tests.txt pytest >=7.1.3,<9.0.0 coverage[toml] >= 6.5.0,< 8.0 -mypy ==1.8.0 +mypy ==1.14.1 dirty-equals ==0.9.0 sqlmodel==0.0.24 flask >=1.1.2,<4.0.0