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
Provenance
- Commit
eb36135- Tree
33610e9- Author
Chris Hallacy <hallacy@openai.com>- Committer
David Lord <davidism@gmail.com>- Parent
ca8e621
3 files changed+11 added−5 removed
modified:src/flask/blueprints.py+4 added-4 removed
160 unmodified lines161 162 .. versionadded:: 0.7163 """164 165- warn_on_modifications = False165 _got_registered_once = False166 167 #: Blueprint local JSON encoder class to use. Set to ``None`` to use168 #: the app's :class:`~flask.Flask.json_encoder`.38 unmodified lines207 self.cli_group = cli_group208 self._blueprints: t.List[t.Tuple["Blueprint", dict]] = []209 210 def _is_setup_finished(self) -> bool:212- return self.warn_on_modifications and self._got_registered_once211+ return self._got_registered_once212 213 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 warn222 223 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 linesmodified:src/flask/scaffold.py+3 added-1 removed
25 unmodified lines26 from .typing import URLDefaultCallable27 from .typing import URLValuePreprocessorCallable28 29 if t.TYPE_CHECKING: # pragma: no cover30- from .wrappers import Response30 from .typing import ErrorHandlerCallable31+ from .wrappers import Response32 33 # a singleton sentinel value for parameter defaults34 _sentinel = object()35 374 unmodified lines410 .. versionadded:: 2.0411 """412 return self._method_route("PATCH", rule, options)413 414+ @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 lines510 :class:`~werkzeug.routing.Rule` object.511 """512 raise NotImplementedError513 514+ @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 linesmodified:CHANGES.rst+4 added
14 unmodified lines15 - ``flask.redirect`` will call ``app.redirect``. :issue:`4569`16 17 - 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`23 24 25 Version 2.1.226 -------------1280 unmodified lines