Coverage for docs_src / dependencies / tutorial003_an_py310.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from typing import Annotated, Any 1qrstuvw

2 

3from fastapi import Depends, FastAPI 1qrstuvw

4 

5app = FastAPI() 1qrstuvw

6 

7 

8fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}] 1qrstuvw

9 

10 

11class CommonQueryParams: 1qrstuvw

12 def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100): 1qrstuvw

13 self.q = q 1xabcdeyfzghijkAlmnop

14 self.skip = skip 1xabcdeyfzghijkAlmnop

15 self.limit = limit 1xabcdeyfzghijkAlmnop

16 

17 

18@app.get("/items/") 1qrstuvw

19async def read_items(commons: Annotated[Any, Depends(CommonQueryParams)]): 1qrstuvw

20 response = {} 1xabcdeyfzghijkAlmnop

21 if commons.q: 1xabcdeyfzghijkAlmnop

22 response.update({"q": commons.q}) 1abcdefBghijklmnop

23 items = fake_items_db[commons.skip : commons.skip + commons.limit] 1xabcdeyfzghijkAlmnop

24 response.update({"items": items}) 1xabcdeyfzghijkAlmnop

25 return response 1xabcdeyfzghijkAlmnop