Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/flask/typing.py: 100%
20 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1import typing as t
3if t.TYPE_CHECKING: # pragma: no cover
4 from _typeshed.wsgi import WSGIApplication # noqa: F401
5 from werkzeug.datastructures import Headers # noqa: F401
6 from werkzeug.wrappers import Response # noqa: F401
8# The possible types that are directly convertible or are a Response object.
9ResponseValue = t.Union[
10 "Response",
11 str,
12 bytes,
13 t.List[t.Any],
14 # Only dict is actually accepted, but Mapping allows for TypedDict.
15 t.Mapping[str, t.Any],
16 t.Iterator[str],
17 t.Iterator[bytes],
18]
20# the possible types for an individual HTTP header
21# This should be a Union, but mypy doesn't pass unless it's a TypeVar.
22HeaderValue = t.Union[str, t.List[str], t.Tuple[str, ...]]
24# the possible types for HTTP headers
25HeadersValue = t.Union[
26 "Headers",
27 t.Mapping[str, HeaderValue],
28 t.Sequence[t.Tuple[str, HeaderValue]],
29]
31# The possible types returned by a route function.
32ResponseReturnValue = t.Union[
33 ResponseValue,
34 t.Tuple[ResponseValue, HeadersValue],
35 t.Tuple[ResponseValue, int],
36 t.Tuple[ResponseValue, int, HeadersValue],
37 "WSGIApplication",
38]
40# Allow any subclass of werkzeug.Response, such as the one from Flask,
41# as a callback argument. Using werkzeug.Response directly makes a
42# callback annotated with flask.Response fail type checking.
43ResponseClass = t.TypeVar("ResponseClass", bound="Response")
45AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named
46AfterRequestCallable = t.Union[
47 t.Callable[[ResponseClass], ResponseClass],
48 t.Callable[[ResponseClass], t.Awaitable[ResponseClass]],
49]
50BeforeFirstRequestCallable = t.Union[
51 t.Callable[[], None], t.Callable[[], t.Awaitable[None]]
52]
53BeforeRequestCallable = t.Union[
54 t.Callable[[], t.Optional[ResponseReturnValue]],
55 t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]],
56]
57ShellContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
58TeardownCallable = t.Union[
59 t.Callable[[t.Optional[BaseException]], None],
60 t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],
61]
62TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
63TemplateFilterCallable = t.Callable[..., t.Any]
64TemplateGlobalCallable = t.Callable[..., t.Any]
65TemplateTestCallable = t.Callable[..., bool]
66URLDefaultCallable = t.Callable[[str, dict], None]
67URLValuePreprocessorCallable = t.Callable[[t.Optional[str], t.Optional[dict]], None]
69# This should take Exception, but that either breaks typing the argument
70# with a specific exception, or decorating multiple times with different
71# exceptions (and using a union type on the argument).
72# https://github.com/pallets/flask/issues/4095
73# https://github.com/pallets/flask/issues/4295
74# https://github.com/pallets/flask/issues/4297
75ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue]
77RouteCallable = t.Union[
78 t.Callable[..., ResponseReturnValue],
79 t.Callable[..., t.Awaitable[ResponseReturnValue]],
80]