Merge remote-tracking branch 'upstream/2.0.x'

This commit is contained in:
Adrian Moennich 2021-05-29 20:55:23 +02:00
commit 6f5870a791
5 changed files with 21 additions and 10 deletions

View file

@ -13,6 +13,12 @@ Version 2.0.2
Unreleased 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 Version 2.0.1
------------- -------------

View file

@ -55,7 +55,7 @@ this structure and take full advantage of Flask's flexibility.
.. image:: flaskr_edit.png .. image:: flaskr_edit.png
:align: center :align: center
:class: screenshot :class: screenshot
:alt: screenshot of login page :alt: screenshot of edit page
:gh:`The tutorial project is available as an example in the Flask :gh:`The tutorial project is available as an example in the Flask
repository <examples/tutorial>`, if you want to compare your project repository <examples/tutorial>`, if you want to compare your project

View file

@ -59,6 +59,7 @@ from .signals import request_tearing_down
from .templating import DispatchingJinjaLoader from .templating import DispatchingJinjaLoader
from .templating import Environment from .templating import Environment
from .typing import AfterRequestCallable from .typing import AfterRequestCallable
from .typing import BeforeFirstRequestCallable
from .typing import BeforeRequestCallable from .typing import BeforeRequestCallable
from .typing import ErrorHandlerCallable from .typing import ErrorHandlerCallable
from .typing import ResponseReturnValue from .typing import ResponseReturnValue
@ -439,7 +440,7 @@ class Flask(Scaffold):
#: :meth:`before_first_request` decorator. #: :meth:`before_first_request` decorator.
#: #:
#: .. versionadded:: 0.8 #: .. 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 #: A list of functions that are called when the application context
#: is destroyed. Since the application context is also torn down #: 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 self.jinja_env.globals[name or f.__name__] = f
@setupmethod @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 """Registers a function to be run before the first request to this
instance of the application. instance of the application.

View file

@ -6,6 +6,7 @@ from .scaffold import _endpoint_from_view_func
from .scaffold import _sentinel from .scaffold import _sentinel
from .scaffold import Scaffold from .scaffold import Scaffold
from .typing import AfterRequestCallable from .typing import AfterRequestCallable
from .typing import BeforeFirstRequestCallable
from .typing import BeforeRequestCallable from .typing import BeforeRequestCallable
from .typing import ErrorHandlerCallable from .typing import ErrorHandlerCallable
from .typing import TeardownCallable from .typing import TeardownCallable
@ -537,8 +538,8 @@ class Blueprint(Scaffold):
return f return f
def before_app_first_request( def before_app_first_request(
self, f: BeforeRequestCallable self, f: BeforeFirstRequestCallable
) -> BeforeRequestCallable: ) -> BeforeFirstRequestCallable:
"""Like :meth:`Flask.before_first_request`. Such a function is """Like :meth:`Flask.before_first_request`. Such a function is
executed before the first request to the application. executed before the first request to the application.
""" """

View file

@ -35,12 +35,13 @@ ResponseReturnValue = t.Union[
AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named
AfterRequestCallable = t.Callable[["Response"], "Response"] AfterRequestCallable = t.Callable[["Response"], "Response"]
BeforeRequestCallable = t.Callable[[], None] BeforeFirstRequestCallable = t.Callable[[], None]
BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]
ErrorHandlerCallable = t.Callable[[Exception], ResponseReturnValue] 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]] TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
TemplateFilterCallable = t.Callable[[t.Any], str] TemplateFilterCallable = t.Callable[..., t.Any]
TemplateGlobalCallable = t.Callable[[], t.Any] TemplateGlobalCallable = t.Callable[..., t.Any]
TemplateTestCallable = t.Callable[[t.Any], bool] TemplateTestCallable = t.Callable[..., bool]
URLDefaultCallable = t.Callable[[str, dict], None] URLDefaultCallable = t.Callable[[str, dict], None]
URLValuePreprocessorCallable = t.Callable[[t.Optional[str], t.Optional[dict]], None] URLValuePreprocessorCallable = t.Callable[[t.Optional[str], t.Optional[dict]], None]