Debian Codegraph @

tests/mypy_test.py

raw symbols SCIP
1 # The goal of this file is to test that mypy "likes" all the combinations of parametrization
2 from typing import Any
3
4 from django.http import HttpRequest
5 from typing_extensions import Annotated
6
7 from ninja import Body, BodyEx, NinjaAPI, P, Schema, Status
8
9
10 class Payload(Schema):
11 x: int
12 y: float
13 s: str
14
15
16 api = NinjaAPI()
17
18
19 @api.post("/old_way")
20 def old_way(request: HttpRequest, data: Payload = Body()) -> Any:
21 data.s.capitalize()
22
23
24 @api.post("/annotated_way")
25 def annotated_way(request: HttpRequest, data: Annotated[Payload, Body()]) -> Any:
26 data.s.capitalize()
27
28
29 @api.post("/new_way")
30 def new_way(request: HttpRequest, data: Body[Payload]) -> Any:
31 data.s.capitalize()
32
33
34 @api.post("/new_way_ex")
35 def new_way_ex(request: HttpRequest, data: BodyEx[Payload, P(title="A title")]) -> Any:
36 data.s.find("")
37
38
39 # -- Status generic --
40
41
42 @api.post("/status_generic")
43 def status_generic(request: HttpRequest) -> Status[dict]:
44 return Status(200, {"key": "value"})
45
46
47 @api.post("/status_generic_schema")
48 def status_generic_schema(request: HttpRequest) -> Status[Payload]:
49 return Status(200, Payload(x=1, y=2.0, s="test"))