| 1 |
from typing import TYPE_CHECKING, Annotated |
| 2 |
|
| 3 |
from fastapi import Depends, FastAPI |
| 4 |
from fastapi.testclient import TestClient |
| 5 |
|
| 6 |
from .utils import needs_py314 |
| 7 |
|
| 8 |
if TYPE_CHECKING: # pragma: no cover |
| 9 |
|
| 10 |
class DummyUser: ... |
| 11 |
|
| 12 |
|
| 13 |
@needs_py314 |
| 14 |
def test_stringified_annotation(): |
| 15 |
# python3.14: Use forward reference without "from __future__ import annotations" |
| 16 |
async def get_current_user() -> DummyUser | None: |
| 17 |
return None |
| 18 |
|
| 19 |
app = FastAPI() |
| 20 |
|
| 21 |
client = TestClient(app) |
| 22 |
|
| 23 |
@app.get("/") |
| 24 |
async def get( |
| 25 |
current_user: Annotated[DummyUser | None, Depends(get_current_user)], |
| 26 |
) -> str: |
| 27 |
return "hello world" |
| 28 |
|
| 29 |
response = client.get("/") |
| 30 |
assert response.status_code == 200 |