-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtyping.py
More file actions
88 lines (69 loc) · 2.33 KB
/
Copy pathtyping.py
File metadata and controls
88 lines (69 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations
from collections.abc import Callable
from typing import Any, AnyStr, Literal, TYPE_CHECKING, TypedDict, Union
from quart import Quart
from quart.datastructures import FileStorage
from quart.typing import (
HeadersValue as QuartHeadersValue,
ResponseReturnValue as QuartResponseReturnValue,
ResponseValue as QuartResponseValue,
StatusCode,
)
from quart.wrappers import Response
from werkzeug.datastructures import Headers
try:
from typing import Protocol
except ImportError:
from typing_extensions import Protocol
try:
from typing import NotRequired
except ImportError:
from typing_extensions import NotRequired
if TYPE_CHECKING:
from attrs import AttrsInstance
from msgspec import Struct
from pydantic import BaseModel
from pydantic.dataclasses import Dataclass
class DataclassProtocol(Protocol):
__dataclass_fields__: dict
__dataclass_params__: dict
__post_init__: Callable | None
ModelTypes = Union["AttrsInstance", "BaseModel", "Dataclass", "DataclassProtocol", "Struct"]
Model = Union[ModelTypes, list[ModelTypes], dict[str, ModelTypes]]
ResponseValue = Union[QuartResponseValue, type[Model]]
HeadersValue = Union[QuartHeadersValue, Model]
ResponseReturnValue = (
QuartResponseReturnValue
| ResponseValue
| tuple[ResponseValue, HeadersValue]
| tuple[ResponseValue, StatusCode]
| tuple[ResponseValue, StatusCode, HeadersValue]
)
class WebsocketProtocol(Protocol):
async def receive_json(self) -> dict: ...
async def send_json(self, data: dict) -> None: ...
class TestClientProtocol(Protocol):
app: Quart
async def _make_request(
self,
path: str,
method: str,
headers: dict | Headers | None,
data: AnyStr | None,
form: dict | None,
files: dict[str, FileStorage] | None,
query_string: dict | None,
json: Any,
scheme: str,
root_path: str,
http_version: str,
scope_base: dict | None,
) -> Response: ...
class PydanticDumpOptions(TypedDict):
by_alias: NotRequired[bool]
exclude_defaults: NotRequired[bool]
exclude_none: NotRequired[bool]
exclude_unset: NotRequired[bool]
round_trip: NotRequired[bool]
serialize_as_any: NotRequired[bool]
warnings: NotRequired[bool | Literal["none", "warn", "error"]]