Fix type annotation for `before_request` and `before_app_request` decorators
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Marat Sharafutdinov · committed by Phil Jones · parent f7adb2c · Browse files · 4 files·+13 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+13 added−6 removed
- other:+13 added−6 removed
Provenance
- Commit
a960236- Tree
b1dc5cd- Author
Marat Sharafutdinov <decaz89@gmail.com>- Committer
Phil Jones <philip.graham.jones@googlemail.com>- Parent
f7adb2c
4 files changed+13 added−6 removed
modified:src/flask/app.py+5 added-2 removed
57 unmodified lines58 from .signals import request_tearing_down59 from .templating import DispatchingJinjaLoader60 from .templating import Environment61 from .typing import AfterRequestCallable62+from .typing import BeforeFirstRequestCallable63 from .typing import BeforeRequestCallable64 from .typing import ErrorHandlerCallable65 from .typing import ResponseReturnValue66 from .typing import TeardownCallable372 unmodified lines439 #: first request to this instance. To register a function, use the440 #: :meth:`before_first_request` decorator.441 #:442 #: .. versionadded:: 0.8442- self.before_first_request_funcs: t.List[BeforeRequestCallable] = []443+ self.before_first_request_funcs: t.List[BeforeFirstRequestCallable] = []444 445 #: A list of functions that are called when the application context446 #: is destroyed. Since the application context is also torn down447 #: if the request ends this is the place to store code that disconnects763 unmodified lines1211 """1212 self.jinja_env.globals[name or f.__name__] = f1213 1214 @setupmethod1214- def before_first_request(self, f: BeforeRequestCallable) -> BeforeRequestCallable:1215+ def before_first_request(1216+ self, f: BeforeFirstRequestCallable1217+ ) -> BeforeFirstRequestCallable:1218 """Registers a function to be run before the first request to this1219 instance of the application.1220 1221 The function will be called without any arguments and its return870 unmodified linesmodified:src/flask/blueprints.py+3 added-2 removed
4 unmodified lines5 from .scaffold import _endpoint_from_view_func6 from .scaffold import _sentinel7 from .scaffold import Scaffold8 from .typing import AfterRequestCallable9+from .typing import BeforeFirstRequestCallable10 from .typing import BeforeRequestCallable11 from .typing import ErrorHandlerCallable12 from .typing import TeardownCallable13 from .typing import TemplateContextProcessorCallable523 unmodified lines537 )538 return f539 540 def before_app_first_request(540- self, f: BeforeRequestCallable541- ) -> BeforeRequestCallable:541+ self, f: BeforeFirstRequestCallable542+ ) -> BeforeFirstRequestCallable:543 """Like :meth:`Flask.before_first_request`. Such a function is544 executed before the first request to the application.545 """546 self.record_once(lambda s: s.app.before_first_request_funcs.append(f))58 unmodified linesmodified:src/flask/typing.py+2 added-1 removed
33 unmodified lines34 ]35 36 AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named37 AfterRequestCallable = t.Callable[["Response"], "Response"]38-BeforeRequestCallable = t.Callable[[], None]38+BeforeFirstRequestCallable = t.Callable[[], None]39+BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]40 ErrorHandlerCallable = t.Callable[[Exception], ResponseReturnValue]41 TeardownCallable = t.Callable[[t.Optional[BaseException]], None]42 TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]43 TemplateFilterCallable = t.Callable[[t.Any], str]4 unmodified linesmodified:CHANGES.rst+3 added-1 removed
3 unmodified lines4 -------------5 6 Unreleased7 8-- Fix type annotation for ``teardown_request``. :issue:`4093`8+- Fix type annotation for ``teardown_request``. :issue:`4093`9+- Fix type annotation for ``before_request`` and ``before_app_request``10+ decorators. :issue:`4104`11 12 13 Version 2.0.114 -------------1154 unmodified lines