from starlette.responses import Response
from starlette.websockets import WebSocket
from typing_extensions import Literal, get_args, get_origin
+from typing_inspection.typing_objects import is_typealiastype
multipart_not_installed_error = (
'Form data requires "python-multipart" to be installed. \n'
depends = None
type_annotation: Any = Any
use_annotation: Any = Any
+ if is_typealiastype(annotation):
+ # unpack in case PEP 695 type syntax is used
+ annotation = annotation.__value__
if annotation is not inspect.Signature.empty:
use_annotation = annotation
type_annotation = annotation
"starlette>=0.40.0,<0.51.0",
"pydantic>=2.7.0",
"typing-extensions>=4.8.0",
+ "typing-inspection>=0.4.2",
"annotated-doc>=0.0.2",
]
--- /dev/null
+from typing import Annotated
+
+from fastapi import Depends, FastAPI
+from fastapi.testclient import TestClient
+from typing_extensions import TypeAliasType
+
+
+async def some_value() -> int:
+ return 123
+
+
+DependedValue = TypeAliasType(
+ "DependedValue", Annotated[int, Depends(some_value)], type_params=()
+)
+
+
+def test_pep695_type_dependencies():
+ app = FastAPI()
+
+ @app.get("/")
+ async def get_with_dep(value: DependedValue) -> str: # noqa
+ return f"value: {value}"
+
+ client = TestClient(app)
+ response = client.get("/")
+ assert response.status_code == 200
+ assert response.text == '"value: 123"'
{ name = "starlette", version = "0.49.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
{ name = "starlette", version = "0.50.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
{ name = "typing-extensions" },
+ { name = "typing-inspection" },
]
[package.optional-dependencies]
{ name = "pyyaml", marker = "extra == 'all'", specifier = ">=5.3.1" },
{ name = "starlette", specifier = ">=0.40.0,<0.51.0" },
{ name = "typing-extensions", specifier = ">=4.8.0" },
+ { name = "typing-inspection", specifier = ">=0.4.2" },
{ name = "ujson", marker = "extra == 'all'", specifier = ">=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0" },
{ name = "uvicorn", extras = ["standard"], marker = "extra == 'all'", specifier = ">=0.12.0" },
{ name = "uvicorn", extras = ["standard"], marker = "extra == 'standard'", specifier = ">=0.12.0" },