👷 Run mypy by pre-commit (#14806)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Motov Yurii 2026-02-03 21:08:08 +03:00 committed by GitHub
parent 2247750d74
commit f3f498100f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 7 deletions

View 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

View 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

View 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

View 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_)