always warn on blueprint setupmethod after registration

This commit is contained in:
Chris Hallacy 2022-05-02 11:33:29 -06:00 committed by David Lord
parent ca8e6217fe
commit eb36135cfe
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
3 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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