From aa6fbf2f5a6265dd0ecaaca03e646c3c2a8f58d2 Mon Sep 17 00:00:00 2001 From: Grey Li Date: Mon, 24 May 2021 16:33:02 +0800 Subject: [PATCH 1/4] Fix typo in docs/tutorial/index.rst --- docs/tutorial/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial/index.rst b/docs/tutorial/index.rst index 103c27a8..d5dc5b3c 100644 --- a/docs/tutorial/index.rst +++ b/docs/tutorial/index.rst @@ -55,7 +55,7 @@ this structure and take full advantage of Flask's flexibility. .. image:: flaskr_edit.png :align: center :class: screenshot - :alt: screenshot of login page + :alt: screenshot of edit page :gh:`The tutorial project is available as an example in the Flask repository `, if you want to compare your project From f7adb2c813c5c10dcab5bc81ee173a6f9fbd406a Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Mon, 24 May 2021 00:31:43 +0200 Subject: [PATCH 2/4] improve typing for `teardown_request` --- CHANGES.rst | 2 ++ src/flask/typing.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 006c0a1f..9c374f56 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ Version 2.0.2 Unreleased +- Fix type annotation for ``teardown_request``. :issue:`4093` + Version 2.0.1 ------------- diff --git a/src/flask/typing.py b/src/flask/typing.py index 5f27308c..60c725ee 100644 --- a/src/flask/typing.py +++ b/src/flask/typing.py @@ -37,7 +37,7 @@ AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints a AfterRequestCallable = t.Callable[["Response"], "Response"] BeforeRequestCallable = t.Callable[[], None] ErrorHandlerCallable = t.Callable[[Exception], ResponseReturnValue] -TeardownCallable = t.Callable[[t.Optional[BaseException]], "Response"] +TeardownCallable = t.Callable[[t.Optional[BaseException]], None] TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]] TemplateFilterCallable = t.Callable[[t.Any], str] TemplateGlobalCallable = t.Callable[[], t.Any] From a960236117442bec67f89c30dfa014e05483da5a Mon Sep 17 00:00:00 2001 From: Marat Sharafutdinov Date: Tue, 25 May 2021 18:04:41 +0300 Subject: [PATCH 3/4] Fix type annotation for `before_request` and `before_app_request` decorators --- CHANGES.rst | 4 +++- src/flask/app.py | 7 +++++-- src/flask/blueprints.py | 5 +++-- src/flask/typing.py | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9c374f56..3e79b5cb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,9 @@ Version 2.0.2 Unreleased -- Fix type annotation for ``teardown_request``. :issue:`4093` +- Fix type annotation for ``teardown_request``. :issue:`4093` +- Fix type annotation for ``before_request`` and ``before_app_request`` + decorators. :issue:`4104` Version 2.0.1 diff --git a/src/flask/app.py b/src/flask/app.py index 3abce3ce..cacb40a5 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -59,6 +59,7 @@ from .signals import request_tearing_down from .templating import DispatchingJinjaLoader from .templating import Environment from .typing import AfterRequestCallable +from .typing import BeforeFirstRequestCallable from .typing import BeforeRequestCallable from .typing import ErrorHandlerCallable from .typing import ResponseReturnValue @@ -439,7 +440,7 @@ class Flask(Scaffold): #: :meth:`before_first_request` decorator. #: #: .. versionadded:: 0.8 - self.before_first_request_funcs: t.List[BeforeRequestCallable] = [] + self.before_first_request_funcs: t.List[BeforeFirstRequestCallable] = [] #: A list of functions that are called when the application context #: is destroyed. Since the application context is also torn down @@ -1211,7 +1212,9 @@ class Flask(Scaffold): self.jinja_env.globals[name or f.__name__] = f @setupmethod - def before_first_request(self, f: BeforeRequestCallable) -> BeforeRequestCallable: + def before_first_request( + self, f: BeforeFirstRequestCallable + ) -> BeforeFirstRequestCallable: """Registers a function to be run before the first request to this instance of the application. diff --git a/src/flask/blueprints.py b/src/flask/blueprints.py index f3913b30..883fc2ff 100644 --- a/src/flask/blueprints.py +++ b/src/flask/blueprints.py @@ -6,6 +6,7 @@ from .scaffold import _endpoint_from_view_func from .scaffold import _sentinel from .scaffold import Scaffold from .typing import AfterRequestCallable +from .typing import BeforeFirstRequestCallable from .typing import BeforeRequestCallable from .typing import ErrorHandlerCallable from .typing import TeardownCallable @@ -537,8 +538,8 @@ class Blueprint(Scaffold): return f def before_app_first_request( - self, f: BeforeRequestCallable - ) -> BeforeRequestCallable: + self, f: BeforeFirstRequestCallable + ) -> BeforeFirstRequestCallable: """Like :meth:`Flask.before_first_request`. Such a function is executed before the first request to the application. """ diff --git a/src/flask/typing.py b/src/flask/typing.py index 60c725ee..8d89839f 100644 --- a/src/flask/typing.py +++ b/src/flask/typing.py @@ -35,7 +35,8 @@ ResponseReturnValue = t.Union[ AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named AfterRequestCallable = t.Callable[["Response"], "Response"] -BeforeRequestCallable = t.Callable[[], None] +BeforeFirstRequestCallable = t.Callable[[], None] +BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]] ErrorHandlerCallable = t.Callable[[Exception], ResponseReturnValue] TeardownCallable = t.Callable[[t.Optional[BaseException]], None] TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]] From 8e589daaf2cec6a10262b8ff88801127f2fa14fd Mon Sep 17 00:00:00 2001 From: default-303 <54715852+default-303@users.noreply.github.com> Date: Sun, 30 May 2021 00:24:35 +0530 Subject: [PATCH 4/4] Fix typing of jinja decorators (#4109) --- CHANGES.rst | 2 ++ src/flask/typing.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3e79b5cb..7920e5ab 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,8 @@ Unreleased - Fix type annotation for ``teardown_request``. :issue:`4093` - Fix type annotation for ``before_request`` and ``before_app_request`` decorators. :issue:`4104` +- Fixed the issue where typing requires template global + decorators to accept functions with no arguments. :issue:`4098` Version 2.0.1 diff --git a/src/flask/typing.py b/src/flask/typing.py index 8d89839f..b1a6cbdc 100644 --- a/src/flask/typing.py +++ b/src/flask/typing.py @@ -40,8 +40,8 @@ BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]] ErrorHandlerCallable = t.Callable[[Exception], ResponseReturnValue] TeardownCallable = t.Callable[[t.Optional[BaseException]], None] TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]] -TemplateFilterCallable = t.Callable[[t.Any], str] -TemplateGlobalCallable = t.Callable[[], t.Any] -TemplateTestCallable = t.Callable[[t.Any], bool] +TemplateFilterCallable = t.Callable[..., t.Any] +TemplateGlobalCallable = t.Callable[..., t.Any] +TemplateTestCallable = t.Callable[..., bool] URLDefaultCallable = t.Callable[[str, dict], None] URLValuePreprocessorCallable = t.Callable[[t.Optional[str], t.Optional[dict]], None]