Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/flask/typing.py: 88%
25 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:03 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:03 +0000
1import typing as t
3if t.TYPE_CHECKING:
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["Response", str, bytes, t.Dict[str, t.Any]]
11# the possible types for an individual HTTP header
12# This should be a Union, but mypy doesn't pass unless it's a TypeVar.
13HeaderValue = t.Union[str, t.List[str], t.Tuple[str, ...]]
15# the possible types for HTTP headers
16HeadersValue = t.Union[
17 "Headers",
18 t.Mapping[str, HeaderValue],
19 t.Sequence[t.Tuple[str, HeaderValue]],
20]
22# The possible types returned by a route function.
23ResponseReturnValue = t.Union[
24 ResponseValue,
25 t.Tuple[ResponseValue, HeadersValue],
26 t.Tuple[ResponseValue, int],
27 t.Tuple[ResponseValue, int, HeadersValue],
28 "WSGIApplication",
29]
31# Allow any subclass of werkzeug.Response, such as the one from Flask,
32# as a callback argument. Using werkzeug.Response directly makes a
33# callback annotated with flask.Response fail type checking.
34ResponseClass = t.TypeVar("ResponseClass", bound="Response")
36AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named
37AfterRequestCallable = t.Callable[[ResponseClass], ResponseClass]
38BeforeFirstRequestCallable = t.Callable[[], None]
39BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]
40TeardownCallable = t.Callable[[t.Optional[BaseException]], None]
41TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
42TemplateFilterCallable = t.Callable[..., t.Any]
43TemplateGlobalCallable = t.Callable[..., t.Any]
44TemplateTestCallable = t.Callable[..., bool]
45URLDefaultCallable = t.Callable[[str, dict], None]
46URLValuePreprocessorCallable = t.Callable[[t.Optional[str], t.Optional[dict]], None]
48# This should take Exception, but that either breaks typing the argument
49# with a specific exception, or decorating multiple times with different
50# exceptions (and using a union type on the argument).
51# https://github.com/pallets/flask/issues/4095
52# https://github.com/pallets/flask/issues/4295
53# https://github.com/pallets/flask/issues/4297
54ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue]
55ErrorHandlerDecorator = t.TypeVar("ErrorHandlerDecorator", bound=ErrorHandlerCallable)
57ViewCallable = t.Callable[..., ResponseReturnValue]
58RouteDecorator = t.TypeVar("RouteDecorator", bound=ViewCallable)