From 4d208b2b9035e24bdf80505571b5b1bac8f9ae7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 1 Mar 2021 20:01:50 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Add=20newly=20required=20type=20?= =?UTF-8?q?annotations=20for=20mypy=20(#2882)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⬆️ Upgrade mypy * 🎨 Add extra type annotations, now required by mypy --- fastapi/dependencies/utils.py | 2 +- fastapi/exceptions.py | 8 ++++---- pyproject.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index fcfaa2cb1..923669b94 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -752,7 +752,7 @@ def get_body_field(*, dependant: Dependant, name: str) -> Optional[ModelField]: for param in flat_dependant.body_params: setattr(param.field_info, "embed", True) model_name = "Body_" + name - BodyModel = create_model(model_name) + BodyModel: Type[BaseModel] = create_model(model_name) for f in flat_dependant.body_params: BodyModel.__fields__[f.name] = get_schema_compatible_field(field=f) required = any(True for f in flat_dependant.body_params if f.required) diff --git a/fastapi/exceptions.py b/fastapi/exceptions.py index 8d92311d4..f4a837bb4 100644 --- a/fastapi/exceptions.py +++ b/fastapi/exceptions.py @@ -1,6 +1,6 @@ -from typing import Any, Dict, Optional, Sequence +from typing import Any, Dict, Optional, Sequence, Type -from pydantic import ValidationError, create_model +from pydantic import BaseModel, ValidationError, create_model from pydantic.error_wrappers import ErrorList from starlette.exceptions import HTTPException as StarletteHTTPException @@ -16,8 +16,8 @@ class HTTPException(StarletteHTTPException): self.headers = headers -RequestErrorModel = create_model("Request") -WebSocketErrorModel = create_model("WebSocket") +RequestErrorModel: Type[BaseModel] = create_model("Request") +WebSocketErrorModel: Type[BaseModel] = create_model("WebSocket") class FastAPIError(RuntimeError): diff --git a/pyproject.toml b/pyproject.toml index 567276036..2f057f5aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ test = [ "pytest ==5.4.3", "pytest-cov ==2.10.0", "pytest-asyncio >=0.14.0,<0.15.0", - "mypy ==0.790", + "mypy ==0.812", "flake8 >=3.8.3,<4.0.0", "black ==20.8b1", "isort >=5.0.6,<6.0.0",