Skip to content
Myr

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

4 files+13 added−6 removed

modified:src/flask/app.py+5 added-2 removed
57 unmodified lines
58from .signals import request_tearing_down59from .templating import DispatchingJinjaLoader60from .templating import Environment61from .typing import AfterRequestCallable62from .typing import BeforeFirstRequestCallable63from .typing import BeforeRequestCallable64from .typing import ErrorHandlerCallable65from .typing import ResponseReturnValue66from .typing import TeardownCallable
372 unmodified lines
439 #: 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] = []444445 #: 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 disconnects
763 unmodified lines
1211 """1212 self.jinja_env.globals[name or f.__name__] = f12131214 @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.12201221 The function will be called without any arguments and its return
870 unmodified lines
modified:src/flask/blueprints.py+3 added-2 removed
4 unmodified lines
5from .scaffold import _endpoint_from_view_func6from .scaffold import _sentinel7from .scaffold import Scaffold8from .typing import AfterRequestCallable9from .typing import BeforeFirstRequestCallable10from .typing import BeforeRequestCallable11from .typing import ErrorHandlerCallable12from .typing import TeardownCallable13from .typing import TemplateContextProcessorCallable
523 unmodified lines
537 )538 return f539540 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 lines
modified:src/flask/typing.py+2 added-1 removed
33 unmodified lines
34]3536AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named37AfterRequestCallable = t.Callable[["Response"], "Response"]38BeforeRequestCallable = t.Callable[[], None]38BeforeFirstRequestCallable = t.Callable[[], None]39BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]40ErrorHandlerCallable = t.Callable[[Exception], ResponseReturnValue]41TeardownCallable = t.Callable[[t.Optional[BaseException]], None]42TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]43TemplateFilterCallable = t.Callable[[t.Any], str]
4 unmodified lines
modified:CHANGES.rst+3 added-1 removed
3 unmodified lines
4-------------56Unreleased78- 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`111213Version 2.0.114-------------
1154 unmodified lines