Skip to content
Myr

always warn on blueprint setupmethod after registration

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Chris Hallacy · committed by David Lord · parent ca8e621 · Browse files · 3 files+11 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+11 added−5 removed

  • other:+11 added−5 removed

3 files+11 added−5 removed

modified:src/flask/blueprints.py+4 added-4 removed
160 unmodified lines
161162 .. versionadded:: 0.7163 """164165 warn_on_modifications = False165 _got_registered_once = False166167 #: Blueprint local JSON encoder class to use. Set to ``None`` to use168 #: the app's :class:`~flask.Flask.json_encoder`.
38 unmodified lines
207 self.cli_group = cli_group208 self._blueprints: t.List[t.Tuple["Blueprint", dict]] = []209210 def _is_setup_finished(self) -> bool:212 return self.warn_on_modifications and self._got_registered_once211 return self._got_registered_once212213 def record(self, func: t.Callable) -> None:214 """Registers a function that is called when the blueprint is215 registered on the application. This function is called with the216 state as argument as returned by the :meth:`make_setup_state`217 method.218 """220 if self._got_registered_once and self.warn_on_modifications:219 if self._got_registered_once:220 # TODO: Upgrade this to an error and unify it setupmethod in 2.3221 from warnings import warn222223 warn(224 Warning(225 "The blueprint was already registered once but is"226 " getting modified now. These changes will not show"227 " up."227 " up.\n This warning will be become an exception in 2.3."228 )229 )230 self.deferred_functions.append(func)231
366 unmodified lines
modified:src/flask/scaffold.py+3 added-1 removed
25 unmodified lines
26from .typing import URLDefaultCallable27from .typing import URLValuePreprocessorCallable2829if t.TYPE_CHECKING: # pragma: no cover30 from .wrappers import Response30 from .typing import ErrorHandlerCallable31 from .wrappers import Response3233# a singleton sentinel value for parameter defaults34_sentinel = object()35
374 unmodified lines
410 .. versionadded:: 2.0411 """412 return self._method_route("PATCH", rule, options)413414 @setupmethod415 def route(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:416 """Decorate a view function to register it with the given URL417 rule and options. Calls :meth:`add_url_rule`, which has more418 details about the implementation.
91 unmodified lines
510 :class:`~werkzeug.routing.Rule` object.511 """512 raise NotImplementedError513514 @setupmethod515 def endpoint(self, endpoint: str) -> t.Callable:516 """Decorate a view function to register it for the given517 endpoint. Used if a rule is added without a ``view_func`` with518 :meth:`add_url_rule`.
356 unmodified lines
modified:CHANGES.rst+4 added
14 unmodified lines
15 - ``flask.redirect`` will call ``app.redirect``. :issue:`4569`1617- Refactor ``register_error_handler`` to consolidate error checking.18 Rewrite some error messages to be more consistent. :issue:`4559`19- Use Blueprint decorators and functions intended for setup after20 registering the blueprint will show a warning. In the next version,21 this will become an error just like the application setup methods.22 :issue:`4571`232425Version 2.1.226-------------
1280 unmodified lines