Skip to content

Commit 145eea8

Browse files
Merge pull request #527 from RonnyPfannschmidt/upgrade-strict
minor ruff and mypy cleanups
2 parents c6f0135 + a34c2d5 commit 145eea8

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ package-data = {"pluggy" = ["py.typed"]}
2727

2828

2929
[tool.ruff.lint]
30-
select = [
31-
"I", # isort
30+
extend-select = [
31+
"I", # isort
32+
"UP",
3233
]
3334

3435
[tool.ruff.lint.isort]

src/pluggy/_hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ def _verify_all_args_are_provided(self, kwargs: Mapping[str, object]) -> None:
489489
if argname not in kwargs.keys()
490490
)
491491
warnings.warn(
492-
"Argument(s) {} which are declared in the hookspec "
493-
"cannot be found in this hook call".format(notincall),
492+
f"Argument(s) {notincall} which are declared in the hookspec "
493+
"cannot be found in this hook call",
494494
stacklevel=2,
495495
)
496496
break

src/pluggy/_manager.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def project_name(self) -> str:
7070
name: str = self.metadata["name"]
7171
return name
7272

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

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

145145
if plugin in self._name2plugin.values():
146146
raise ValueError(
147-
"Plugin already registered under a different name: %s=%s\n%s"
148-
% (plugin_name, plugin, self._name2plugin)
147+
"Plugin already registered under a different name: "
148+
f"{plugin_name}={plugin}\n{self._name2plugin}"
149149
)
150150

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

336336
assert hook.spec is not None
@@ -342,15 +342,10 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None:
342342
if notinspec:
343343
raise PluginValidationError(
344344
hookimpl.plugin,
345-
"Plugin %r for hook %r\nhookimpl definition: %s\n"
346-
"Argument(s) %s are declared in the hookimpl but "
347-
"can not be found in the hookspec"
348-
% (
349-
hookimpl.plugin_name,
350-
hook.name,
351-
_formatdef(hookimpl.function),
352-
notinspec,
353-
),
345+
f"Plugin {hookimpl.plugin_name!r} for hook {hook.name!r}\n"
346+
f"hookimpl definition: {_formatdef(hookimpl.function)}\n"
347+
f"Argument(s) {notinspec} are declared in the hookimpl but "
348+
"can not be found in the hookspec",
354349
)
355350

356351
if hook.spec.warn_on_impl_args:
@@ -364,18 +359,18 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None:
364359
) and not inspect.isgeneratorfunction(hookimpl.function):
365360
raise PluginValidationError(
366361
hookimpl.plugin,
367-
"Plugin %r for hook %r\nhookimpl definition: %s\n"
362+
f"Plugin {hookimpl.plugin_name!r} for hook {hook.name!r}\n"
363+
f"hookimpl definition: {_formatdef(hookimpl.function)}\n"
368364
"Declared as wrapper=True or hookwrapper=True "
369-
"but function is not a generator function"
370-
% (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
365+
"but function is not a generator function",
371366
)
372367

373368
if hookimpl.wrapper and hookimpl.hookwrapper:
374369
raise PluginValidationError(
375370
hookimpl.plugin,
376-
"Plugin %r for hook %r\nhookimpl definition: %s\n"
377-
"The wrapper=True and hookwrapper=True options are mutually exclusive"
378-
% (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
371+
f"Plugin {hookimpl.plugin_name!r} for hook {hook.name!r}\n"
372+
f"hookimpl definition: {_formatdef(hookimpl.function)}\n"
373+
"The wrapper=True and hookwrapper=True options are mutually exclusive",
379374
)
380375

381376
def check_pending(self) -> None:
@@ -390,8 +385,7 @@ def check_pending(self) -> None:
390385
if not hookimpl.optionalhook:
391386
raise PluginValidationError(
392387
hookimpl.plugin,
393-
"unknown hook %r in plugin %r"
394-
% (name, hookimpl.plugin),
388+
f"unknown hook {name!r} in plugin {hookimpl.plugin!r}",
395389
)
396390

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

0 commit comments

Comments
 (0)