Coverage for tests / test_stringified_annotation_dependency_py314.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from typing import TYPE_CHECKING, Annotated 1bcde

2 

3from fastapi import Depends, FastAPI 1bcde

4from fastapi.testclient import TestClient 1bcde

5 

6from .utils import needs_py314 1bcde

7 

8if TYPE_CHECKING: # pragma: no cover 1bcde

9 

10 class DummyUser: ... 

11 

12 

13@needs_py314 1bcde

14def test_stringified_annotation(): 1bcde

15 # python3.14: Use forward reference without "from __future__ import annotations" 

16 async def get_current_user() -> DummyUser | None: 1a

17 return None 1a

18 

19 app = FastAPI() 1a

20 

21 client = TestClient(app) 1a

22 

23 @app.get("/") 1a

24 async def get( 1a

25 current_user: Annotated[DummyUser | None, Depends(get_current_user)], 

26 ) -> str: 

27 return "hello world" 1a

28 

29 response = client.get("/") 1a

30 assert response.status_code == 200 1a