Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
typing.py91 linesDownload Raw Back to flask
1from __future__ import annotations2 3import typing as t4 5if t.TYPE_CHECKING:  # pragma: no cover6    from _typeshed.wsgi import WSGIApplication  # noqa: F4017    from werkzeug.datastructures import Headers  # noqa: F4018    from werkzeug.sansio.response import Response  # noqa: F4019 10# The possible types that are directly convertible or are a Response object.11ResponseValue = t.Union[12    "Response",13    str,14    bytes,15    t.List[t.Any],16    # Only dict is actually accepted, but Mapping allows for TypedDict.17    t.Mapping[str, t.Any],18    t.Iterator[str],19    t.Iterator[bytes],20]21 22# the possible types for an individual HTTP header23# This should be a Union, but mypy doesn't pass unless it's a TypeVar.24HeaderValue = t.Union[str, t.List[str], t.Tuple[str, ...]]25 26# the possible types for HTTP headers27HeadersValue = t.Union[28    "Headers",29    t.Mapping[str, HeaderValue],30    t.Sequence[t.Tuple[str, HeaderValue]],31]32 33# The possible types returned by a route function.34ResponseReturnValue = t.Union[35    ResponseValue,36    t.Tuple[ResponseValue, HeadersValue],37    t.Tuple[ResponseValue, int],38    t.Tuple[ResponseValue, int, HeadersValue],39    "WSGIApplication",40]41 42# Allow any subclass of werkzeug.Response, such as the one from Flask,43# as a callback argument. Using werkzeug.Response directly makes a44# callback annotated with flask.Response fail type checking.45ResponseClass = t.TypeVar("ResponseClass", bound="Response")46 47AppOrBlueprintKey = t.Optional[str]  # The App key is None, whereas blueprints are named48AfterRequestCallable = t.Union[49    t.Callable[[ResponseClass], ResponseClass],50    t.Callable[[ResponseClass], t.Awaitable[ResponseClass]],51]52BeforeFirstRequestCallable = t.Union[53    t.Callable[[], None], t.Callable[[], t.Awaitable[None]]54]55BeforeRequestCallable = t.Union[56    t.Callable[[], t.Optional[ResponseReturnValue]],57    t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]],58]59ShellContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]60TeardownCallable = t.Union[61    t.Callable[[t.Optional[BaseException]], None],62    t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],63]64TemplateContextProcessorCallable = t.Union[65    t.Callable[[], t.Dict[str, t.Any]],66    t.Callable[[], t.Awaitable[t.Dict[str, t.Any]]],67]68TemplateFilterCallable = t.Callable[..., t.Any]69TemplateGlobalCallable = t.Callable[..., t.Any]70TemplateTestCallable = t.Callable[..., bool]71URLDefaultCallable = t.Callable[[str, t.Dict[str, t.Any]], None]72URLValuePreprocessorCallable = t.Callable[73    [t.Optional[str], t.Optional[t.Dict[str, t.Any]]], None74]75 76# This should take Exception, but that either breaks typing the argument77# with a specific exception, or decorating multiple times with different78# exceptions (and using a union type on the argument).79# https://github.com/pallets/flask/issues/409580# https://github.com/pallets/flask/issues/429581# https://github.com/pallets/flask/issues/429782ErrorHandlerCallable = t.Union[83    t.Callable[[t.Any], ResponseReturnValue],84    t.Callable[[t.Any], t.Awaitable[ResponseReturnValue]],85]86 87RouteCallable = t.Union[88    t.Callable[..., ResponseReturnValue],89    t.Callable[..., t.Awaitable[ResponseReturnValue]],90]91 
codekingpro/portable-devtools · Team Ai