Browse Source

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
pull/14201/head
Roberto Bertó 9 months ago
parent
commit
db9cc165b6
  1. 4
      fastapi/_compat/__init__.py
  2. 2
      fastapi/_compat/v1.py

4
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:

2
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

Loading…
Cancel
Save