diff --git a/fastapi/_compat/shared.py b/fastapi/_compat/shared.py index 023b5bba2..29cfb11fd 100644 --- a/fastapi/_compat/shared.py +++ b/fastapi/_compat/shared.py @@ -97,7 +97,7 @@ def value_is_sequence(value: Any) -> bool: def _annotation_is_complex(annotation: Union[Type[Any], None]) -> bool: - types_tuple: tuple[Type[Any], ...] = (BaseModel, Mapping, UploadFile) + types_tuple: Tuple[Type[Any], ...] = (BaseModel, Mapping, UploadFile) if "pydantic.v1" in sys.modules: # only now touch v1 (already used by app) types_tuple += (_v1.BaseModel,) diff --git a/fastapi/_compat/v2.py b/fastapi/_compat/v2.py index bf81aff1d..318ffc341 100644 --- a/fastapi/_compat/v2.py +++ b/fastapi/_compat/v2.py @@ -471,3 +471,8 @@ def get_long_model_name(model: TypeModelOrEnum) -> str: def _is_model_class(value: Any) -> bool: """Check if a value is a Pydantic model class.""" return lenient_issubclass(value, BaseModel) + + +def _is_model_field(value: Any) -> bool: + """Check if a value is a Pydantic model field.""" + return isinstance(value, ModelField)