Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/flask/typing.py: 0%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import annotations
3import collections.abc as cabc
4import typing as t
6if t.TYPE_CHECKING: # pragma: no cover
7 from _typeshed.wsgi import WSGIApplication # noqa: F401
8 from werkzeug.datastructures import Headers # noqa: F401
9 from werkzeug.sansio.response import Response # noqa: F401
11# The possible types that are directly convertible or are a Response object.
12ResponseValue = t.Union[
13 "Response",
14 str,
15 bytes,
16 list[t.Any],
17 # Only dict is actually accepted, but Mapping allows for TypedDict.
18 t.Mapping[str, t.Any],
19 t.Iterator[str],
20 t.Iterator[bytes],
21 cabc.AsyncIterable[str], # for Quart, until App is generic.
22 cabc.AsyncIterable[bytes],
23]
25# the possible types for an individual HTTP header
26HeaderValue = str | list[str] | tuple[str, ...]
28# the possible types for HTTP headers
29HeadersValue = t.Union[
30 "Headers",
31 t.Mapping[str, HeaderValue],
32 t.Sequence[tuple[str, HeaderValue]],
33]
35# The possible types returned by a route function.
36ResponseReturnValue = t.Union[
37 ResponseValue,
38 tuple[ResponseValue, HeadersValue],
39 tuple[ResponseValue, int],
40 tuple[ResponseValue, int, HeadersValue],
41 "WSGIApplication",
42]
44# Allow any subclass of werkzeug.Response, such as the one from Flask,
45# as a callback argument. Using werkzeug.Response directly makes a
46# callback annotated with flask.Response fail type checking.
47ResponseClass = t.TypeVar("ResponseClass", bound="Response")
49AppOrBlueprintKey = str | None # The App key is None, whereas blueprints are named
50AfterRequestCallable = (
51 t.Callable[[ResponseClass], ResponseClass]
52 | t.Callable[[ResponseClass], t.Awaitable[ResponseClass]]
53)
54BeforeFirstRequestCallable = t.Callable[[], None] | t.Callable[[], t.Awaitable[None]]
55BeforeRequestCallable = (
56 t.Callable[[], ResponseReturnValue | None]
57 | t.Callable[[], t.Awaitable[ResponseReturnValue | None]]
58)
59ShellContextProcessorCallable = t.Callable[[], dict[str, t.Any]]
60TeardownCallable = (
61 t.Callable[[BaseException | None], None]
62 | t.Callable[[BaseException | None], t.Awaitable[None]]
63)
64TemplateContextProcessorCallable = (
65 t.Callable[[], dict[str, t.Any]] | t.Callable[[], t.Awaitable[dict[str, t.Any]]]
66)
67TemplateFilterCallable = t.Callable[..., t.Any]
68TemplateGlobalCallable = t.Callable[..., t.Any]
69TemplateTestCallable = t.Callable[..., bool]
70URLDefaultCallable = t.Callable[[str, dict[str, t.Any]], None]
71URLValuePreprocessorCallable = t.Callable[[str | None, dict[str, t.Any] | None], None]
73# This should take Exception, but that either breaks typing the argument
74# with a specific exception, or decorating multiple times with different
75# exceptions (and using a union type on the argument).
76# https://github.com/pallets/flask/issues/4095
77# https://github.com/pallets/flask/issues/4295
78# https://github.com/pallets/flask/issues/4297
79ErrorHandlerCallable = (
80 t.Callable[[t.Any], ResponseReturnValue]
81 | t.Callable[[t.Any], t.Awaitable[ResponseReturnValue]]
82)
84RouteCallable = (
85 t.Callable[..., ResponseReturnValue]
86 | t.Callable[..., t.Awaitable[ResponseReturnValue]]
87)