[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] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -27,12 +27,12 @@ from typing import Union
from ._result import Result
_T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., object])
_T = TypeVar('_T')
_F = TypeVar('_F', bound=Callable[..., object])
_Namespace = Union[ModuleType, type]
_Plugin = object
_HookExec = Callable[
[str, Sequence["HookImpl"], Mapping[str, object], bool],
[str, Sequence['HookImpl'], Mapping[str, object], bool],
Union[object, List[object]],
]
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
@ -79,7 +79,7 @@ class HookspecMarker:
functions if the :class:`PluginManager` uses the same project name.
"""
__slots__ = ("project_name",)
__slots__ = ('project_name',)
def __init__(self, project_name: str) -> None:
self.project_name: Final = project_name
@ -133,13 +133,13 @@ class HookspecMarker:
def setattr_hookspec_opts(func: _F) -> _F:
if historic and firstresult:
raise ValueError("cannot have a historic firstresult hook")
raise ValueError('cannot have a historic firstresult hook')
opts: HookspecOpts = {
"firstresult": firstresult,
"historic": historic,
"warn_on_impl": warn_on_impl,
'firstresult': firstresult,
'historic': historic,
'warn_on_impl': warn_on_impl,
}
setattr(func, self.project_name + "_spec", opts)
setattr(func, self.project_name + '_spec', opts)
return func
if function is not None:
@ -157,7 +157,7 @@ class HookimplMarker:
functions if the :class:`PluginManager` uses the same project name.
"""
__slots__ = ("project_name",)
__slots__ = ('project_name',)
def __init__(self, project_name: str) -> None:
self.project_name: Final = project_name
@ -251,14 +251,14 @@ class HookimplMarker:
def setattr_hookimpl_opts(func: _F) -> _F:
opts: HookimplOpts = {
"wrapper": wrapper,
"hookwrapper": hookwrapper,
"optionalhook": optionalhook,
"tryfirst": tryfirst,
"trylast": trylast,
"specname": specname,
'wrapper': wrapper,
'hookwrapper': hookwrapper,
'optionalhook': optionalhook,
'tryfirst': tryfirst,
'trylast': trylast,
'specname': specname,
}
setattr(func, self.project_name + "_impl", opts)
setattr(func, self.project_name + '_impl', opts)
return func
if function is None:
@ -268,15 +268,15 @@ class HookimplMarker:
def normalize_hookimpl_opts(opts: HookimplOpts) -> None:
opts.setdefault("tryfirst", False)
opts.setdefault("trylast", False)
opts.setdefault("wrapper", False)
opts.setdefault("hookwrapper", False)
opts.setdefault("optionalhook", False)
opts.setdefault("specname", None)
opts.setdefault('tryfirst', False)
opts.setdefault('trylast', False)
opts.setdefault('wrapper', False)
opts.setdefault('hookwrapper', False)
opts.setdefault('optionalhook', False)
opts.setdefault('specname', None)
_PYPY = hasattr(sys, "pypy_version_info")
_PYPY = hasattr(sys, 'pypy_version_info')
def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
@ -293,14 +293,14 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
return (), ()
elif not inspect.isroutine(func): # callable object?
try:
func = getattr(func, "__call__", func)
func = getattr(func, '__call__', func)
except Exception:
return (), ()
try:
# func MUST be a function or method here or we won't parse any args.
sig = inspect.signature(
func.__func__ if inspect.ismethod(func) else func # type:ignore[arg-type]
func.__func__ if inspect.ismethod(func) else func, # type:ignore[arg-type]
)
except TypeError:
return (), ()
@ -320,8 +320,8 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
param.default
for param in _valid_params.values()
if param.default is not param.empty
)
or None
) or
None
)
if defaults:
@ -333,12 +333,12 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
# strip any implicit instance arg
# pypy3 uses "obj" instead of "self" for default dunder methods
if not _PYPY:
implicit_names: tuple[str, ...] = ("self",)
implicit_names: tuple[str, ...] = ('self',)
else:
implicit_names = ("self", "obj")
implicit_names = ('self', 'obj')
if args:
qualname: str = getattr(func, "__qualname__", "")
if inspect.ismethod(func) or ("." in qualname and args[0] in implicit_names):
qualname: str = getattr(func, '__qualname__', '')
if inspect.ismethod(func) or ('.' in qualname and args[0] in implicit_names):
args = args[1:]
return args, kwargs
@ -349,7 +349,7 @@ class HookRelay:
"""Hook holder object for performing 1:N hook calls where N is the number
of registered plugins."""
__slots__ = ("__dict__",)
__slots__ = ('__dict__',)
def __init__(self) -> None:
""":meta private:"""
@ -371,11 +371,11 @@ class HookCaller:
"""A caller of all registered implementations of a hook specification."""
__slots__ = (
"name",
"spec",
"_hookexec",
"_hookimpls",
"_call_history",
'name',
'spec',
'_hookexec',
'_hookimpls',
'_call_history',
)
def __init__(
@ -416,11 +416,11 @@ class HookCaller:
) -> None:
if self.spec is not None:
raise ValueError(
f"Hook {self.spec.name!r} is already registered "
f"within namespace {self.spec.namespace}"
f'Hook {self.spec.name!r} is already registered '
f'within namespace {self.spec.namespace}',
)
self.spec = HookSpec(specmodule_or_class, self.name, spec_opts)
if spec_opts.get("historic"):
if spec_opts.get('historic'):
self._call_history = []
def is_historic(self) -> bool:
@ -432,7 +432,7 @@ class HookCaller:
if method.plugin == plugin:
del self._hookimpls[i]
return
raise ValueError(f"plugin {plugin!r} not found")
raise ValueError(f'plugin {plugin!r} not found')
def get_hookimpls(self) -> list[HookImpl]:
"""Get all registered hook implementations for this hook."""
@ -463,22 +463,22 @@ class HookCaller:
self._hookimpls.insert(i + 1, hookimpl)
def __repr__(self) -> str:
return f"<HookCaller {self.name!r}>"
return f'<HookCaller {self.name!r}>'
def _verify_all_args_are_provided(self, kwargs: Mapping[str, object]) -> None:
# This is written to avoid expensive operations when not needed.
if self.spec:
for argname in self.spec.argnames:
if argname not in kwargs:
notincall = ", ".join(
notincall = ', '.join(
repr(argname)
for argname in self.spec.argnames
# Avoid self.spec.argnames - kwargs.keys() - doesn't preserve order.
if argname not in kwargs.keys()
)
warnings.warn(
"Argument(s) {} which are declared in the hookspec "
"cannot be found in this hook call".format(notincall),
'Argument(s) {} which are declared in the hookspec '
'cannot be found in this hook call'.format(notincall),
stacklevel=2,
)
break
@ -494,9 +494,9 @@ class HookCaller:
"""
assert (
not self.is_historic()
), "Cannot directly call a historic hook - use call_historic instead."
), 'Cannot directly call a historic hook - use call_historic instead.'
self._verify_all_args_are_provided(kwargs)
firstresult = self.spec.opts.get("firstresult", False) if self.spec else False
firstresult = self.spec.opts.get('firstresult', False) if self.spec else False
# Copy because plugins may register other plugins during iteration (#438).
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
@ -528,37 +528,37 @@ class HookCaller:
result_callback(x)
def call_extra(
self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object]
self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object],
) -> Any:
"""Call the hook with some additional temporarily participating
methods using the specified ``kwargs`` as call parameters, see
:ref:`call_extra`."""
assert (
not self.is_historic()
), "Cannot directly call a historic hook - use call_historic instead."
), 'Cannot directly call a historic hook - use call_historic instead.'
self._verify_all_args_are_provided(kwargs)
opts: HookimplOpts = {
"wrapper": False,
"hookwrapper": False,
"optionalhook": False,
"trylast": False,
"tryfirst": False,
"specname": None,
'wrapper': False,
'hookwrapper': False,
'optionalhook': False,
'trylast': False,
'tryfirst': False,
'specname': None,
}
hookimpls = self._hookimpls.copy()
for method in methods:
hookimpl = HookImpl(None, "<temp>", method, opts)
hookimpl = HookImpl(None, '<temp>', method, opts)
# Find last non-tryfirst nonwrapper method.
i = len(hookimpls) - 1
while i >= 0 and (
# Skip wrappers.
(hookimpls[i].hookwrapper or hookimpls[i].wrapper)
(hookimpls[i].hookwrapper or hookimpls[i].wrapper) or
# Skip tryfirst nonwrappers.
or hookimpls[i].tryfirst
hookimpls[i].tryfirst
):
i -= 1
hookimpls.insert(i + 1, hookimpl)
firstresult = self.spec.opts.get("firstresult", False) if self.spec else False
firstresult = self.spec.opts.get('firstresult', False) if self.spec else False
return self._hookexec(self.name, hookimpls, kwargs, firstresult)
def _maybe_apply_history(self, method: HookImpl) -> None:
@ -592,8 +592,8 @@ class _SubsetHookCaller(HookCaller):
# proxy, however that adds more overhead and is more tricky to implement.
__slots__ = (
"_orig",
"_remove_plugins",
'_orig',
'_remove_plugins',
)
def __init__(self, orig: HookCaller, remove_plugins: AbstractSet[_Plugin]) -> None:
@ -619,7 +619,7 @@ class _SubsetHookCaller(HookCaller):
return self._orig._call_history
def __repr__(self) -> str:
return f"<_SubsetHookCaller {self.name!r}>"
return f'<_SubsetHookCaller {self.name!r}>'
@final
@ -627,17 +627,17 @@ class HookImpl:
"""A hook implementation in a :class:`HookCaller`."""
__slots__ = (
"function",
"argnames",
"kwargnames",
"plugin",
"opts",
"plugin_name",
"wrapper",
"hookwrapper",
"optionalhook",
"tryfirst",
"trylast",
'function',
'argnames',
'kwargnames',
'plugin',
'opts',
'plugin_name',
'wrapper',
'hookwrapper',
'optionalhook',
'tryfirst',
'trylast',
)
def __init__(
@ -662,34 +662,34 @@ class HookImpl:
#: The name of the plugin which defined this hook implementation.
self.plugin_name: Final = plugin_name
#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
self.wrapper: Final = hook_impl_opts["wrapper"]
self.wrapper: Final = hook_impl_opts['wrapper']
#: Whether the hook implementation is an :ref:`old-style wrapper
#: <old_style_hookwrappers>`.
self.hookwrapper: Final = hook_impl_opts["hookwrapper"]
self.hookwrapper: Final = hook_impl_opts['hookwrapper']
#: Whether validation against a hook specification is :ref:`optional
#: <optionalhook>`.
self.optionalhook: Final = hook_impl_opts["optionalhook"]
self.optionalhook: Final = hook_impl_opts['optionalhook']
#: Whether to try to order this hook implementation :ref:`first
#: <callorder>`.
self.tryfirst: Final = hook_impl_opts["tryfirst"]
self.tryfirst: Final = hook_impl_opts['tryfirst']
#: Whether to try to order this hook implementation :ref:`last
#: <callorder>`.
self.trylast: Final = hook_impl_opts["trylast"]
self.trylast: Final = hook_impl_opts['trylast']
def __repr__(self) -> str:
return f"<HookImpl plugin_name={self.plugin_name!r}, plugin={self.plugin!r}>"
return f'<HookImpl plugin_name={self.plugin_name!r}, plugin={self.plugin!r}>'
@final
class HookSpec:
__slots__ = (
"namespace",
"function",
"name",
"argnames",
"kwargnames",
"opts",
"warn_on_impl",
'namespace',
'function',
'name',
'argnames',
'kwargnames',
'opts',
'warn_on_impl',
)
def __init__(self, namespace: _Namespace, name: str, opts: HookspecOpts) -> None:
@ -698,4 +698,4 @@ class HookSpec:
self.name = name
self.argnames, self.kwargnames = varnames(self.function)
self.opts = opts
self.warn_on_impl = opts.get("warn_on_impl")
self.warn_on_impl = opts.get('warn_on_impl')