]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
👷 Run mypy by pre-commit (#14806)
authorMotov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Tue, 3 Feb 2026 18:08:08 +0000 (21:08 +0300)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 18:08:08 +0000 (19:08 +0100)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
.pre-commit-config.yaml
fastapi/_compat/v2.py
fastapi/dependencies/utils.py
fastapi/utils.py

index d88b70b7b64d7277eab28239da7996b776458a7f..64b84bfbd215fdb87f43fcb806ea0443dc210a72 100644 (file)
@@ -30,6 +30,13 @@ repos:
         language: unsupported
         types: [python]
 
+      - id: local-mypy
+        name: mypy check
+        entry: uv run mypy fastapi
+        require_serial: true
+        language: unsupported
+        pass_filenames: false
+
       - id: add-permalinks-pages
         language: unsupported
         name: add-permalinks-pages
index 25b68145368c56e137d8488043d684aaeea4e775..dae78a32e0ceb9c0bccdb3e288a8c783e34ab5cf 100644 (file)
@@ -477,7 +477,7 @@ def get_model_fields(model: type[BaseModel]) -> list[ModelField]:
 
 @lru_cache
 def get_cached_model_fields(model: type[BaseModel]) -> list[ModelField]:
-    return get_model_fields(model)  # type: ignore[return-value]
+    return get_model_fields(model)
 
 
 # Duplicate of several schema functions from Pydantic v1 to make them compatible with
@@ -500,13 +500,13 @@ def get_model_name_map(unique_models: TypeModelSet) -> dict[TypeModelOrEnum, str
 
 
 def get_compat_model_name_map(fields: list[ModelField]) -> ModelNameMap:
-    all_flat_models = set()
+    all_flat_models: TypeModelSet = set()
 
     v2_model_fields = [field for field in fields if isinstance(field, ModelField)]
     v2_flat_models = get_flat_models_from_fields(v2_model_fields, known_models=set())
-    all_flat_models = all_flat_models.union(v2_flat_models)  # type: ignore[arg-type]
+    all_flat_models = all_flat_models.union(v2_flat_models)
 
-    model_name_map = get_model_name_map(all_flat_models)  # type: ignore[arg-type]
+    model_name_map = get_model_name_map(all_flat_models)
     return model_name_map
 
 
index 45e1ff3ed15736fc138717cc524e0796209480c4..2afc734ba4b137ec3ba2331c4691db9847c64d8c 100644 (file)
@@ -399,7 +399,7 @@ def analyze_param(
         if isinstance(fastapi_annotation, FieldInfo):
             # Copy `field_info` because we mutate `field_info.default` below.
             field_info = copy_field_info(
-                field_info=fastapi_annotation,  # type: ignore[arg-type]
+                field_info=fastapi_annotation,
                 annotation=use_annotation,
             )
             assert (
@@ -433,7 +433,7 @@ def analyze_param(
             "Cannot specify FastAPI annotations in `Annotated` and default value"
             f" together for {param_name!r}"
         )
-        field_info = value  # type: ignore[assignment]
+        field_info = value
         if isinstance(field_info, FieldInfo):
             field_info.annotation = type_annotation
 
index 78fdcbb5b4e3264faa58e1f6a55892084f132b3e..1c3a0881f7d0e202828cf4b30d649e57de0ecdcb 100644 (file)
@@ -90,7 +90,7 @@ def create_model_field(
     field_info = field_info or FieldInfo(annotation=type_, default=default, alias=alias)
     kwargs = {"mode": mode, "name": name, "field_info": field_info}
     try:
-        return v2.ModelField(**kwargs)  # type: ignore[return-value,arg-type]
+        return v2.ModelField(**kwargs)  # type: ignore[arg-type]
     except PydanticSchemaGenerationError:
         raise fastapi.exceptions.FastAPIError(
             _invalid_args_message.format(type_=type_)