Browse Source

♻️ Remove Python 3.9 specific logic

pull/14897/head
Sebastián Ramírez 5 months ago
parent
commit
1d76345f98
  1. 13
      fastapi/_compat/shared.py
  2. 25
      fastapi/dependencies/utils.py

13
fastapi/_compat/shared.py

@ -21,14 +21,11 @@ from typing_extensions import TypeGuard, get_args, get_origin
_T = TypeVar("_T") _T = TypeVar("_T")
# Copy from Pydantic: pydantic/_internal/_typing_extra.py # Copy from Pydantic: pydantic/_internal/_typing_extra.py
if sys.version_info < (3, 10): WithArgsTypes: tuple[Any, ...] = (
WithArgsTypes: tuple[Any, ...] = (typing._GenericAlias, types.GenericAlias) # type: ignore[attr-defined] typing._GenericAlias, # type: ignore[attr-defined]
else: types.GenericAlias,
WithArgsTypes: tuple[Any, ...] = ( types.UnionType,
typing._GenericAlias, # type: ignore[attr-defined] ) # pyright: ignore[reportAttributeAccessIssue]
types.GenericAlias,
types.UnionType,
) # pyright: ignore[reportAttributeAccessIssue]
PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2]) PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2])

25
fastapi/dependencies/utils.py

@ -199,20 +199,17 @@ def get_flat_params(dependant: Dependant) -> list[ModelField]:
def _get_signature(call: Callable[..., Any]) -> inspect.Signature: def _get_signature(call: Callable[..., Any]) -> inspect.Signature:
if sys.version_info >= (3, 10): try:
try: signature = inspect.signature(call, eval_str=True)
signature = inspect.signature(call, eval_str=True) except NameError:
except NameError: # Handle type annotations with if TYPE_CHECKING, not used by FastAPI
# Handle type annotations with if TYPE_CHECKING, not used by FastAPI # e.g. dependency return types
# e.g. dependency return types if sys.version_info >= (3, 14):
if sys.version_info >= (3, 14): from annotationlib import Format
from annotationlib import Format
signature = inspect.signature(call, annotation_format=Format.FORWARDREF)
signature = inspect.signature(call, annotation_format=Format.FORWARDREF) else:
else: signature = inspect.signature(call)
signature = inspect.signature(call)
else:
signature = inspect.signature(call)
return signature return signature

Loading…
Cancel
Save