From 6830d918669255fbd32bae10f28a228591ea1ef7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Jun 2022 01:50:56 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/flask/blueprints.py | 32 ++++++++------------------------ src/flask/debughelpers.py | 1 + 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/flask/blueprints.py b/src/flask/blueprints.py index b73a9536..7310bae9 100644 --- a/src/flask/blueprints.py +++ b/src/flask/blueprints.py @@ -69,7 +69,6 @@ class BlueprintSetupState: self.url_defaults = dict(self.blueprint.url_values_defaults) self.url_defaults.update(self.options.get("url_defaults", ())) - def add_url_rule( self, rule: str, @@ -169,7 +168,6 @@ class Blueprint(Scaffold): #: the app's :class:`~flask.Flask.json_decoder`. json_decoder = None - def __init__( self, name: str, @@ -206,7 +204,6 @@ class Blueprint(Scaffold): self.cli_group = cli_group self._blueprints: t.List[t.Tuple["Blueprint", dict]] = [] - def _check_setup_finished(self, f_name: str) -> None: # TODO - This method is missing a docstring - please advise if self._got_registered_once: @@ -225,7 +222,6 @@ class Blueprint(Scaffold): stacklevel=3, ) - @setupmethod def record(self, func: t.Callable) -> None: """Registers a function that is called when the blueprint is @@ -235,7 +231,6 @@ class Blueprint(Scaffold): """ self.deferred_functions.append(func) - @setupmethod def record_once(self, func: t.Callable) -> None: """Works like :meth:`record` but wraps the function in another @@ -243,13 +238,13 @@ class Blueprint(Scaffold): blueprint is registered a second time on the application, the function passed is not called. """ + def wrapper(state: BlueprintSetupState) -> None: if state.first_registration: func(state) return self.record(update_wrapper(wrapper, func)) - def make_setup_state( self, app: "Flask", options: dict, first_registration: bool = False ) -> BlueprintSetupState: @@ -259,7 +254,6 @@ class Blueprint(Scaffold): """ return BlueprintSetupState(self, app, options, first_registration) - @setupmethod def register_blueprint(self, blueprint: "Blueprint", **options: t.Any) -> None: """Register a :class:`~flask.Blueprint` on this blueprint. Keyword @@ -278,7 +272,6 @@ class Blueprint(Scaffold): raise ValueError("Cannot register a blueprint on itself") self._blueprints.append((blueprint, options)) - def register(self, app: "Flask", options: dict) -> None: """Called by :meth:`Flask.register_blueprint` to register all views and callbacks registered on the blueprint with the @@ -336,13 +329,11 @@ class Blueprint(Scaffold): # Merge blueprint data into parent. if first_bp_registration or first_name_registration: - def extend(bp_dict, parent_dict): for key, values in bp_dict.items(): key = name if key is None else f"{name}.{key}" parent_dict[key].extend(values) - for key, value in self.error_handler_spec.items(): key = name if key is None else f"{name}.{key}" value = defaultdict( @@ -407,7 +398,6 @@ class Blueprint(Scaffold): bp_options["name_prefix"] = name blueprint.register(app, bp_options) - @setupmethod def add_url_rule( self, @@ -436,7 +426,6 @@ class Blueprint(Scaffold): ) ) - @setupmethod def app_template_filter( self, name: t.Optional[str] = None @@ -447,13 +436,13 @@ class Blueprint(Scaffold): :param name: the optional name of the filter, otherwise the function name will be used. """ + def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable: self.add_app_template_filter(f, name=name) return f return decorator - @setupmethod def add_app_template_filter( self, f: ft.TemplateFilterCallable, name: t.Optional[str] = None @@ -465,12 +454,12 @@ class Blueprint(Scaffold): :param name: the optional name of the filter, otherwise the function name will be used. """ + def register_template(state: BlueprintSetupState) -> None: state.app.jinja_env.filters[name or f.__name__] = f self.record_once(register_template) - @setupmethod def app_template_test( self, name: t.Optional[str] = None @@ -483,6 +472,7 @@ class Blueprint(Scaffold): :param name: the optional name of the test, otherwise the function name will be used. """ + def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable: self.add_app_template_test(f, name=name) return f @@ -502,12 +492,12 @@ class Blueprint(Scaffold): :param name: the optional name of the test, otherwise the function name will be used. """ + def register_template(state: BlueprintSetupState) -> None: state.app.jinja_env.tests[name or f.__name__] = f self.record_once(register_template) - @setupmethod def app_template_global( self, name: t.Optional[str] = None @@ -520,13 +510,13 @@ class Blueprint(Scaffold): :param name: the optional name of the global, otherwise the function name will be used. """ + def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable: self.add_app_template_global(f, name=name) return f return decorator - @setupmethod def add_app_template_global( self, f: ft.TemplateGlobalCallable, name: t.Optional[str] = None @@ -540,12 +530,12 @@ class Blueprint(Scaffold): :param name: the optional name of the global, otherwise the function name will be used. """ + def register_template(state: BlueprintSetupState) -> None: state.app.jinja_env.globals[name or f.__name__] = f self.record_once(register_template) - @setupmethod def before_app_request( self, f: ft.BeforeRequestCallable @@ -558,7 +548,6 @@ class Blueprint(Scaffold): ) return f - @setupmethod def before_app_first_request( self, f: ft.BeforeFirstRequestCallable @@ -583,7 +572,6 @@ class Blueprint(Scaffold): self.record_once(lambda s: s.app.before_first_request_funcs.append(f)) return f - def after_app_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable: """Like :meth:`Flask.after_request` but for a blueprint. Such a function is executed after each request, even if outside of the blueprint. @@ -593,7 +581,6 @@ class Blueprint(Scaffold): ) return f - @setupmethod def teardown_app_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable: """Like :meth:`Flask.teardown_request` but for a blueprint. Such a @@ -605,7 +592,6 @@ class Blueprint(Scaffold): ) return f - @setupmethod def app_context_processor( self, f: ft.TemplateContextProcessorCallable @@ -618,7 +604,6 @@ class Blueprint(Scaffold): ) return f - @setupmethod def app_errorhandler( self, code: t.Union[t.Type[Exception], int] @@ -626,13 +611,13 @@ class Blueprint(Scaffold): """Like :meth:`Flask.errorhandler` but for a blueprint. This handler is used for all requests, even if outside of the blueprint. """ + def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator: self.record_once(lambda s: s.app.errorhandler(code)(f)) return f return decorator - @setupmethod def app_url_value_preprocessor( self, f: ft.URLValuePreprocessorCallable @@ -643,7 +628,6 @@ class Blueprint(Scaffold): ) return f - @setupmethod def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable: """Same as :meth:`url_defaults` but application wide.""" diff --git a/src/flask/debughelpers.py b/src/flask/debughelpers.py index ff556d69..7d7d2b1b 100644 --- a/src/flask/debughelpers.py +++ b/src/flask/debughelpers.py @@ -9,6 +9,7 @@ class UnexpectedUnicodeError(AssertionError, UnicodeError): """Raised in places where we want some better error reporting for unexpected unicode or binary data. """ + pass