Skip to content
Myr

use bound typevar to accept Flask and Werkzeug Response classes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Justin Bull · committed by David Lord · parent a4f63e0 · Browse files · 2 files+8 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−2 removed

  • other:+8 added−2 removed

2 files+8 added−2 removed

modified:src/flask/typing.py+7 added-2 removed
2 unmodified lines
34if t.TYPE_CHECKING:5 from _typeshed.wsgi import WSGIApplication # noqa: F4016 from werkzeug.datastructures import Headers # noqa: F4017 from werkzeug.wrappers.response import Response # noqa: F4017 from werkzeug.wrappers import Response # noqa: F40189# The possible types that are directly convertible or are a Response object.10ResponseValue = t.Union[11 "Response",
22 unmodified lines
34 t.Tuple[ResponseValue, StatusCode, HeadersValue],35 "WSGIApplication",36]3738# Allow any subclass of werkzeug.Response, such as the one from Flask,39# as a callback argument. Using werkzeug.Response directly makes a40# callback annotated with flask.Response fail type checking.41ResponseClass = t.TypeVar("ResponseClass", bound="Response")4243AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named39AfterRequestCallable = t.Callable[["Response"], "Response"]44AfterRequestCallable = t.Callable[[ResponseClass], ResponseClass]45BeforeFirstRequestCallable = t.Callable[[], None]46BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]47TeardownCallable = t.Callable[[t.Optional[BaseException]], None]48TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
12 unmodified lines
modified:CHANGES.rst+1 added
5 unmodified lines
6Unreleased78- Inline some optional imports that are only used for certain CLI9 commands. :pr:`4606`10- Relax type annotation for ``after_request`` functions. :issue:`4600`111213Version 2.1.214-------------
1280 unmodified lines