From db9cc165b699e9f4e76fe0985f24931fdb089d0d 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:20:10 +0000 Subject: [PATCH] fix: replace built-in generics with typing.* for Python 3.8 compatibility - Replace dict[str, Any] with Dict[str, Any] in runtime aliases - Fix JsonSchemaValue aliases in _compat/__init__.py and _compat/v1.py - Add Dict import to _compat/__init__.py - Resolves TypeError: 'type' object is not subscriptable in Python 3.8 - Maintains compatibility with Python 3.8+ while keeping modern syntax in main code --- fastapi/_compat/__init__.py | 4 ++-- fastapi/_compat/v1.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fastapi/_compat/__init__.py b/fastapi/_compat/__init__.py index e7a92efec..6674a2462 100644 --- a/fastapi/_compat/__init__.py +++ b/fastapi/_compat/__init__.py @@ -10,7 +10,7 @@ detects the Pydantic version and provides the appropriate symbols. from __future__ import annotations -from typing import Any +from typing import Any, Dict # Import the v1 proxy module - this provides lazy loading and controlled warnings # Don't import at module level to avoid warnings @@ -102,7 +102,7 @@ from .shared import value_is_sequence as value_is_sequence # Export V1 symbols as Any to avoid import-time access CoreSchema = Any GetJsonSchemaHandler = Any -JsonSchemaValue = dict[str, Any] +JsonSchemaValue = Dict[str, Any] def _normalize_errors(errors: Any) -> Any: diff --git a/fastapi/_compat/v1.py b/fastapi/_compat/v1.py index 17f6c7f96..adbec897a 100644 --- a/fastapi/_compat/v1.py +++ b/fastapi/_compat/v1.py @@ -223,6 +223,6 @@ def serialize_sequence_value(*, field: Any, value: Any) -> Any: # Type aliases for backward compatibility GetJsonSchemaHandler = Any -JsonSchemaValue = dict[str, Any] +JsonSchemaValue = Dict[str, Any] CoreSchema = Any Url = Any