mirror of https://github.com/pallets/flask.git
always warn on blueprint setupmethod after registration
This commit is contained in:
parent
ca8e6217fe
commit
eb36135cfe
|
@ -16,6 +16,10 @@ Unreleased
|
|||
|
||||
- Refactor ``register_error_handler`` to consolidate error checking.
|
||||
Rewrite some error messages to be more consistent. :issue:`4559`
|
||||
- Use Blueprint decorators and functions intended for setup after
|
||||
registering the blueprint will show a warning. In the next version,
|
||||
this will become an error just like the application setup methods.
|
||||
:issue:`4571`
|
||||
|
||||
|
||||
Version 2.1.2
|
||||
|
|
|
@ -162,7 +162,6 @@ class Blueprint(Scaffold):
|
|||
.. versionadded:: 0.7
|
||||
"""
|
||||
|
||||
warn_on_modifications = False
|
||||
_got_registered_once = False
|
||||
|
||||
#: Blueprint local JSON encoder class to use. Set to ``None`` to use
|
||||
|
@ -209,7 +208,7 @@ class Blueprint(Scaffold):
|
|||
self._blueprints: t.List[t.Tuple["Blueprint", dict]] = []
|
||||
|
||||
def _is_setup_finished(self) -> bool:
|
||||
return self.warn_on_modifications and self._got_registered_once
|
||||
return self._got_registered_once
|
||||
|
||||
def record(self, func: t.Callable) -> None:
|
||||
"""Registers a function that is called when the blueprint is
|
||||
|
@ -217,14 +216,15 @@ class Blueprint(Scaffold):
|
|||
state as argument as returned by the :meth:`make_setup_state`
|
||||
method.
|
||||
"""
|
||||
if self._got_registered_once and self.warn_on_modifications:
|
||||
if self._got_registered_once:
|
||||
# TODO: Upgrade this to an error and unify it setupmethod in 2.3
|
||||
from warnings import warn
|
||||
|
||||
warn(
|
||||
Warning(
|
||||
"The blueprint was already registered once but is"
|
||||
" getting modified now. These changes will not show"
|
||||
" up."
|
||||
" up.\n This warning will be become an exception in 2.3."
|
||||
)
|
||||
)
|
||||
self.deferred_functions.append(func)
|
||||
|
|
|
@ -27,8 +27,8 @@ from .typing import URLDefaultCallable
|
|||
from .typing import URLValuePreprocessorCallable
|
||||
|
||||
if t.TYPE_CHECKING: # pragma: no cover
|
||||
from .wrappers import Response
|
||||
from .typing import ErrorHandlerCallable
|
||||
from .wrappers import Response
|
||||
|
||||
# a singleton sentinel value for parameter defaults
|
||||
_sentinel = object()
|
||||
|
@ -411,6 +411,7 @@ class Scaffold:
|
|||
"""
|
||||
return self._method_route("PATCH", rule, options)
|
||||
|
||||
@setupmethod
|
||||
def route(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:
|
||||
"""Decorate a view function to register it with the given URL
|
||||
rule and options. Calls :meth:`add_url_rule`, which has more
|
||||
|
@ -510,6 +511,7 @@ class Scaffold:
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@setupmethod
|
||||
def endpoint(self, endpoint: str) -> t.Callable:
|
||||
"""Decorate a view function to register it for the given
|
||||
endpoint. Used if a rule is added without a ``view_func`` with
|
||||
|
|
Loading…
Reference in New Issue