| 1 |
from typing import Annotated |
| 2 |
|
| 3 |
from fastapi import Depends, FastAPI |
| 4 |
from fastapi.testclient import TestClient |
| 5 |
from typing_extensions import TypeAliasType |
| 6 |
|
| 7 |
|
| 8 |
async def some_value() -> int: |
| 9 |
return 123 |
| 10 |
|
| 11 |
|
| 12 |
DependedValue = TypeAliasType( |
| 13 |
"DependedValue", Annotated[int, Depends(some_value)], type_params=() |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
def test_pep695_type_dependencies(): |
| 18 |
app = FastAPI() |
| 19 |
|
| 20 |
@app.get("/") |
| 21 |
async def get_with_dep(value: DependedValue) -> str: # noqa |
| 22 |
return f"value: {value}" |
| 23 |
|
| 24 |
client = TestClient(app) |
| 25 |
response = client.get("/") |
| 26 |
assert response.status_code == 200 |
| 27 |
assert response.text == '"value: 123"' |