[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2022-06-18 01:50:56 +00:00
parent 8a72c556d6
commit 6830d91866
2 changed files with 9 additions and 24 deletions

View file

@ -69,7 +69,6 @@ class BlueprintSetupState:
self.url_defaults = dict(self.blueprint.url_values_defaults) self.url_defaults = dict(self.blueprint.url_values_defaults)
self.url_defaults.update(self.options.get("url_defaults", ())) self.url_defaults.update(self.options.get("url_defaults", ()))
def add_url_rule( def add_url_rule(
self, self,
rule: str, rule: str,
@ -169,7 +168,6 @@ class Blueprint(Scaffold):
#: the app's :class:`~flask.Flask.json_decoder`. #: the app's :class:`~flask.Flask.json_decoder`.
json_decoder = None json_decoder = None
def __init__( def __init__(
self, self,
name: str, name: str,
@ -206,7 +204,6 @@ class Blueprint(Scaffold):
self.cli_group = cli_group self.cli_group = cli_group
self._blueprints: t.List[t.Tuple["Blueprint", dict]] = [] self._blueprints: t.List[t.Tuple["Blueprint", dict]] = []
def _check_setup_finished(self, f_name: str) -> None: def _check_setup_finished(self, f_name: str) -> None:
# TODO - This method is missing a docstring - please advise # TODO - This method is missing a docstring - please advise
if self._got_registered_once: if self._got_registered_once:
@ -225,7 +222,6 @@ class Blueprint(Scaffold):
stacklevel=3, stacklevel=3,
) )
@setupmethod @setupmethod
def record(self, func: t.Callable) -> None: def record(self, func: t.Callable) -> None:
"""Registers a function that is called when the blueprint is """Registers a function that is called when the blueprint is
@ -235,7 +231,6 @@ class Blueprint(Scaffold):
""" """
self.deferred_functions.append(func) self.deferred_functions.append(func)
@setupmethod @setupmethod
def record_once(self, func: t.Callable) -> None: def record_once(self, func: t.Callable) -> None:
"""Works like :meth:`record` but wraps the function in another """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 blueprint is registered a second time on the application, the
function passed is not called. function passed is not called.
""" """
def wrapper(state: BlueprintSetupState) -> None: def wrapper(state: BlueprintSetupState) -> None:
if state.first_registration: if state.first_registration:
func(state) func(state)
return self.record(update_wrapper(wrapper, func)) return self.record(update_wrapper(wrapper, func))
def make_setup_state( def make_setup_state(
self, app: "Flask", options: dict, first_registration: bool = False self, app: "Flask", options: dict, first_registration: bool = False
) -> BlueprintSetupState: ) -> BlueprintSetupState:
@ -259,7 +254,6 @@ class Blueprint(Scaffold):
""" """
return BlueprintSetupState(self, app, options, first_registration) return BlueprintSetupState(self, app, options, first_registration)
@setupmethod @setupmethod
def register_blueprint(self, blueprint: "Blueprint", **options: t.Any) -> None: def register_blueprint(self, blueprint: "Blueprint", **options: t.Any) -> None:
"""Register a :class:`~flask.Blueprint` on this blueprint. Keyword """Register a :class:`~flask.Blueprint` on this blueprint. Keyword
@ -278,7 +272,6 @@ class Blueprint(Scaffold):
raise ValueError("Cannot register a blueprint on itself") raise ValueError("Cannot register a blueprint on itself")
self._blueprints.append((blueprint, options)) self._blueprints.append((blueprint, options))
def register(self, app: "Flask", options: dict) -> None: def register(self, app: "Flask", options: dict) -> None:
"""Called by :meth:`Flask.register_blueprint` to register all """Called by :meth:`Flask.register_blueprint` to register all
views and callbacks registered on the blueprint with the views and callbacks registered on the blueprint with the
@ -336,13 +329,11 @@ class Blueprint(Scaffold):
# Merge blueprint data into parent. # Merge blueprint data into parent.
if first_bp_registration or first_name_registration: if first_bp_registration or first_name_registration:
def extend(bp_dict, parent_dict): def extend(bp_dict, parent_dict):
for key, values in bp_dict.items(): for key, values in bp_dict.items():
key = name if key is None else f"{name}.{key}" key = name if key is None else f"{name}.{key}"
parent_dict[key].extend(values) parent_dict[key].extend(values)
for key, value in self.error_handler_spec.items(): for key, value in self.error_handler_spec.items():
key = name if key is None else f"{name}.{key}" key = name if key is None else f"{name}.{key}"
value = defaultdict( value = defaultdict(
@ -407,7 +398,6 @@ class Blueprint(Scaffold):
bp_options["name_prefix"] = name bp_options["name_prefix"] = name
blueprint.register(app, bp_options) blueprint.register(app, bp_options)
@setupmethod @setupmethod
def add_url_rule( def add_url_rule(
self, self,
@ -436,7 +426,6 @@ class Blueprint(Scaffold):
) )
) )
@setupmethod @setupmethod
def app_template_filter( def app_template_filter(
self, name: t.Optional[str] = None self, name: t.Optional[str] = None
@ -447,13 +436,13 @@ class Blueprint(Scaffold):
:param name: the optional name of the filter, otherwise the :param name: the optional name of the filter, otherwise the
function name will be used. function name will be used.
""" """
def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable: def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable:
self.add_app_template_filter(f, name=name) self.add_app_template_filter(f, name=name)
return f return f
return decorator return decorator
@setupmethod @setupmethod
def add_app_template_filter( def add_app_template_filter(
self, f: ft.TemplateFilterCallable, name: t.Optional[str] = None 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 :param name: the optional name of the filter, otherwise the
function name will be used. function name will be used.
""" """
def register_template(state: BlueprintSetupState) -> None: def register_template(state: BlueprintSetupState) -> None:
state.app.jinja_env.filters[name or f.__name__] = f state.app.jinja_env.filters[name or f.__name__] = f
self.record_once(register_template) self.record_once(register_template)
@setupmethod @setupmethod
def app_template_test( def app_template_test(
self, name: t.Optional[str] = None self, name: t.Optional[str] = None
@ -483,6 +472,7 @@ class Blueprint(Scaffold):
:param name: the optional name of the test, otherwise the :param name: the optional name of the test, otherwise the
function name will be used. function name will be used.
""" """
def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable: def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable:
self.add_app_template_test(f, name=name) self.add_app_template_test(f, name=name)
return f return f
@ -502,12 +492,12 @@ class Blueprint(Scaffold):
:param name: the optional name of the test, otherwise the :param name: the optional name of the test, otherwise the
function name will be used. function name will be used.
""" """
def register_template(state: BlueprintSetupState) -> None: def register_template(state: BlueprintSetupState) -> None:
state.app.jinja_env.tests[name or f.__name__] = f state.app.jinja_env.tests[name or f.__name__] = f
self.record_once(register_template) self.record_once(register_template)
@setupmethod @setupmethod
def app_template_global( def app_template_global(
self, name: t.Optional[str] = None self, name: t.Optional[str] = None
@ -520,13 +510,13 @@ class Blueprint(Scaffold):
:param name: the optional name of the global, otherwise the :param name: the optional name of the global, otherwise the
function name will be used. function name will be used.
""" """
def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable: def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable:
self.add_app_template_global(f, name=name) self.add_app_template_global(f, name=name)
return f return f
return decorator return decorator
@setupmethod @setupmethod
def add_app_template_global( def add_app_template_global(
self, f: ft.TemplateGlobalCallable, name: t.Optional[str] = None 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 :param name: the optional name of the global, otherwise the
function name will be used. function name will be used.
""" """
def register_template(state: BlueprintSetupState) -> None: def register_template(state: BlueprintSetupState) -> None:
state.app.jinja_env.globals[name or f.__name__] = f state.app.jinja_env.globals[name or f.__name__] = f
self.record_once(register_template) self.record_once(register_template)
@setupmethod @setupmethod
def before_app_request( def before_app_request(
self, f: ft.BeforeRequestCallable self, f: ft.BeforeRequestCallable
@ -558,7 +548,6 @@ class Blueprint(Scaffold):
) )
return f return f
@setupmethod @setupmethod
def before_app_first_request( def before_app_first_request(
self, f: ft.BeforeFirstRequestCallable self, f: ft.BeforeFirstRequestCallable
@ -583,7 +572,6 @@ class Blueprint(Scaffold):
self.record_once(lambda s: s.app.before_first_request_funcs.append(f)) self.record_once(lambda s: s.app.before_first_request_funcs.append(f))
return f return f
def after_app_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable: def after_app_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:
"""Like :meth:`Flask.after_request` but for a blueprint. Such a function """Like :meth:`Flask.after_request` but for a blueprint. Such a function
is executed after each request, even if outside of the blueprint. is executed after each request, even if outside of the blueprint.
@ -593,7 +581,6 @@ class Blueprint(Scaffold):
) )
return f return f
@setupmethod @setupmethod
def teardown_app_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable: def teardown_app_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable:
"""Like :meth:`Flask.teardown_request` but for a blueprint. Such a """Like :meth:`Flask.teardown_request` but for a blueprint. Such a
@ -605,7 +592,6 @@ class Blueprint(Scaffold):
) )
return f return f
@setupmethod @setupmethod
def app_context_processor( def app_context_processor(
self, f: ft.TemplateContextProcessorCallable self, f: ft.TemplateContextProcessorCallable
@ -618,7 +604,6 @@ class Blueprint(Scaffold):
) )
return f return f
@setupmethod @setupmethod
def app_errorhandler( def app_errorhandler(
self, code: t.Union[t.Type[Exception], int] self, code: t.Union[t.Type[Exception], int]
@ -626,13 +611,13 @@ class Blueprint(Scaffold):
"""Like :meth:`Flask.errorhandler` but for a blueprint. This """Like :meth:`Flask.errorhandler` but for a blueprint. This
handler is used for all requests, even if outside of the blueprint. handler is used for all requests, even if outside of the blueprint.
""" """
def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator: def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator:
self.record_once(lambda s: s.app.errorhandler(code)(f)) self.record_once(lambda s: s.app.errorhandler(code)(f))
return f return f
return decorator return decorator
@setupmethod @setupmethod
def app_url_value_preprocessor( def app_url_value_preprocessor(
self, f: ft.URLValuePreprocessorCallable self, f: ft.URLValuePreprocessorCallable
@ -643,7 +628,6 @@ class Blueprint(Scaffold):
) )
return f return f
@setupmethod @setupmethod
def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable: def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable:
"""Same as :meth:`url_defaults` but application wide.""" """Same as :meth:`url_defaults` but application wide."""

View file

@ -9,6 +9,7 @@ class UnexpectedUnicodeError(AssertionError, UnicodeError):
"""Raised in places where we want some better error reporting for """Raised in places where we want some better error reporting for
unexpected unicode or binary data. unexpected unicode or binary data.
""" """
pass pass