Skip to content

Commit

Permalink
Merge pull request #527 from RonnyPfannschmidt/upgrade-strict
Browse files Browse the repository at this point in the history
minor ruff and mypy cleanups
  • Loading branch information
RonnyPfannschmidt authored Sep 3, 2024
2 parents c6f0135 + a34c2d5 commit 145eea8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ package-data = {"pluggy" = ["py.typed"]}


[tool.ruff.lint]
select = [
"I", # isort
extend-select = [
"I", # isort
"UP",
]

[tool.ruff.lint.isort]
Expand Down
4 changes: 2 additions & 2 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ def _verify_all_args_are_provided(self, kwargs: Mapping[str, object]) -> None:
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),
f"Argument(s) {notincall} which are declared in the hookspec "
"cannot be found in this hook call",
stacklevel=2,
)
break
Expand Down
42 changes: 18 additions & 24 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def project_name(self) -> str:
name: str = self.metadata["name"]
return name

def __getattr__(self, attr: str, default=None):
def __getattr__(self, attr: str, default: Any | None = None) -> Any:
return getattr(self._dist, attr, default)

def __dir__(self) -> list[str]:
Expand Down Expand Up @@ -138,14 +138,14 @@ def register(self, plugin: _Plugin, name: str | None = None) -> str | None:
if self._name2plugin.get(plugin_name, -1) is None:
return None # blocked plugin, return None to indicate no registration
raise ValueError(
"Plugin name already registered: %s=%s\n%s"
% (plugin_name, plugin, self._name2plugin)
"Plugin name already registered: "
f"{plugin_name}={plugin}\n{self._name2plugin}"
)

if plugin in self._name2plugin.values():
raise ValueError(
"Plugin already registered under a different name: %s=%s\n%s"
% (plugin_name, plugin, self._name2plugin)
"Plugin already registered under a different name: "
f"{plugin_name}={plugin}\n{self._name2plugin}"
)

# XXX if an error happens we should make sure no state has been
Expand Down Expand Up @@ -329,8 +329,8 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None:
if hook.is_historic() and (hookimpl.hookwrapper or hookimpl.wrapper):
raise PluginValidationError(
hookimpl.plugin,
"Plugin %r\nhook %r\nhistoric incompatible with yield/wrapper/hookwrapper"
% (hookimpl.plugin_name, hook.name),
f"Plugin {hookimpl.plugin_name!r}\nhook {hook.name!r}\n"
"historic incompatible with yield/wrapper/hookwrapper",
)

assert hook.spec is not None
Expand All @@ -342,15 +342,10 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None:
if notinspec:
raise PluginValidationError(
hookimpl.plugin,
"Plugin %r for hook %r\nhookimpl definition: %s\n"
"Argument(s) %s are declared in the hookimpl but "
"can not be found in the hookspec"
% (
hookimpl.plugin_name,
hook.name,
_formatdef(hookimpl.function),
notinspec,
),
f"Plugin {hookimpl.plugin_name!r} for hook {hook.name!r}\n"
f"hookimpl definition: {_formatdef(hookimpl.function)}\n"
f"Argument(s) {notinspec} are declared in the hookimpl but "
"can not be found in the hookspec",
)

if hook.spec.warn_on_impl_args:
Expand All @@ -364,18 +359,18 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None:
) and not inspect.isgeneratorfunction(hookimpl.function):
raise PluginValidationError(
hookimpl.plugin,
"Plugin %r for hook %r\nhookimpl definition: %s\n"
f"Plugin {hookimpl.plugin_name!r} for hook {hook.name!r}\n"
f"hookimpl definition: {_formatdef(hookimpl.function)}\n"
"Declared as wrapper=True or hookwrapper=True "
"but function is not a generator function"
% (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
"but function is not a generator function",
)

if hookimpl.wrapper and hookimpl.hookwrapper:
raise PluginValidationError(
hookimpl.plugin,
"Plugin %r for hook %r\nhookimpl definition: %s\n"
"The wrapper=True and hookwrapper=True options are mutually exclusive"
% (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
f"Plugin {hookimpl.plugin_name!r} for hook {hook.name!r}\n"
f"hookimpl definition: {_formatdef(hookimpl.function)}\n"
"The wrapper=True and hookwrapper=True options are mutually exclusive",
)

def check_pending(self) -> None:
Expand All @@ -390,8 +385,7 @@ def check_pending(self) -> None:
if not hookimpl.optionalhook:
raise PluginValidationError(
hookimpl.plugin,
"unknown hook %r in plugin %r"
% (name, hookimpl.plugin),
f"unknown hook {name!r} in plugin {hookimpl.plugin!r}",
)

def load_setuptools_entrypoints(self, group: str, name: str | None = None) -> int:
Expand Down

0 comments on commit 145eea8

Please sign in to comment.