Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
typing.py94 linesDownload Raw Back to flask
1from __future__ import annotations2 3import collections.abc as cabc4import typing as t5 6if t.TYPE_CHECKING:  # pragma: no cover7    from _typeshed.wsgi import WSGIApplication  # noqa: F4018    from werkzeug.datastructures import Headers  # noqa: F4019    from werkzeug.sansio.response import Response  # noqa: F40110 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]24 25# the possible types for an individual HTTP header26# This should be a Union, but mypy doesn't pass unless it's a TypeVar.27HeaderValue = t.Union[str, list[str], tuple[str, ...]]28 29# the possible types for HTTP headers30HeadersValue = t.Union[31    "Headers",32    t.Mapping[str, HeaderValue],33    t.Sequence[tuple[str, HeaderValue]],34]35 36# The possible types returned by a route function.37ResponseReturnValue = t.Union[38    ResponseValue,39    tuple[ResponseValue, HeadersValue],40    tuple[ResponseValue, int],41    tuple[ResponseValue, int, HeadersValue],42    "WSGIApplication",43]44 45# Allow any subclass of werkzeug.Response, such as the one from Flask,46# as a callback argument. Using werkzeug.Response directly makes a47# callback annotated with flask.Response fail type checking.48ResponseClass = t.TypeVar("ResponseClass", bound="Response")49 50AppOrBlueprintKey = t.Optional[str]  # The App key is None, whereas blueprints are named51AfterRequestCallable = t.Union[52    t.Callable[[ResponseClass], ResponseClass],53    t.Callable[[ResponseClass], t.Awaitable[ResponseClass]],54]55BeforeFirstRequestCallable = t.Union[56    t.Callable[[], None], t.Callable[[], t.Awaitable[None]]57]58BeforeRequestCallable = t.Union[59    t.Callable[[], t.Optional[ResponseReturnValue]],60    t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]],61]62ShellContextProcessorCallable = t.Callable[[], dict[str, t.Any]]63TeardownCallable = t.Union[64    t.Callable[[t.Optional[BaseException]], None],65    t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],66]67TemplateContextProcessorCallable = t.Union[68    t.Callable[[], dict[str, t.Any]],69    t.Callable[[], t.Awaitable[dict[str, t.Any]]],70]71TemplateFilterCallable = t.Callable[..., t.Any]72TemplateGlobalCallable = t.Callable[..., t.Any]73TemplateTestCallable = t.Callable[..., bool]74URLDefaultCallable = t.Callable[[str, dict[str, t.Any]], None]75URLValuePreprocessorCallable = t.Callable[76    [t.Optional[str], t.Optional[dict[str, t.Any]]], None77]78 79# This should take Exception, but that either breaks typing the argument80# with a specific exception, or decorating multiple times with different81# exceptions (and using a union type on the argument).82# https://github.com/pallets/flask/issues/409583# https://github.com/pallets/flask/issues/429584# https://github.com/pallets/flask/issues/429785ErrorHandlerCallable = t.Union[86    t.Callable[[t.Any], ResponseReturnValue],87    t.Callable[[t.Any], t.Awaitable[ResponseReturnValue]],88]89 90RouteCallable = t.Union[91    t.Callable[..., ResponseReturnValue],92    t.Callable[..., t.Awaitable[ResponseReturnValue]],93]94 
codekingpro/portable-devtools · Team Ai