From fb00f2679d41f1f0a38dc90879ed62eee04b6022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bert=C3=B3?= <463349+robertoberto@users.noreply.github.com> Date: Sat, 18 Oct 2025 04:24:10 +0000 Subject: [PATCH] fix: complete Python 3.8 compatibility fixes - Fix tuple[Type[Any], ...] to Tuple[Type[Any], ...] in shared.py - Add missing _is_model_field function to v2.py - All tests now pass on Python 3.8 without TypeError - Import-time compatibility fully restored for Python 3.8 --- fastapi/_compat/shared.py | 2 +- fastapi/_compat/v2.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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)