diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b9f521a..f2a8176c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.15.22" + rev: "v0.16.0" hooks: - id: ruff-check args: ["--fix"] diff --git a/src/pluggy/__init__.py b/src/pluggy/__init__.py index 3d81d0a3..32c7eae5 100644 --- a/src/pluggy/__init__.py +++ b/src/pluggy/__init__.py @@ -1,18 +1,18 @@ __all__ = [ - "__version__", - "PluginManager", - "PluginValidationError", - "HookCaller", "HookCallError", - "HookspecOpts", - "HookimplOpts", + "HookCaller", "HookImpl", "HookRelay", - "HookspecMarker", "HookimplMarker", - "Result", - "PluggyWarning", + "HookimplOpts", + "HookspecMarker", + "HookspecOpts", "PluggyTeardownRaisedWarning", + "PluggyWarning", + "PluginManager", + "PluginValidationError", + "Result", + "__version__", ] from ._hooks import HookCaller from ._hooks import HookImpl diff --git a/src/pluggy/_callers.py b/src/pluggy/_callers.py index 450db1a7..8b4b1477 100644 --- a/src/pluggy/_callers.py +++ b/src/pluggy/_callers.py @@ -74,7 +74,7 @@ def _warn_teardown_exception( f"A plugin raised an exception during an old-style hookwrapper teardown.\n" f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n" f"{type(e).__name__}: {e}\n" - f"For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501 + f"For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" ) warnings.warn(PluggyTeardownRaisedWarning(msg), stacklevel=6) diff --git a/src/pluggy/_hooks.py b/src/pluggy/_hooks.py index f079d3b7..700fe67d 100644 --- a/src/pluggy/_hooks.py +++ b/src/pluggy/_hooks.py @@ -99,8 +99,8 @@ def __call__( warn_on_impl_args: Mapping[str, Warning] | None = None, ) -> _F: ... - @overload # noqa: F811 - def __call__( # noqa: F811 + @overload + def __call__( self, function: None = ..., firstresult: bool = ..., @@ -109,7 +109,7 @@ def __call__( # noqa: F811 warn_on_impl_args: Mapping[str, Warning] | None = ..., ) -> Callable[[_F], _F]: ... - def __call__( # noqa: F811 + def __call__( self, function: _F | None = None, firstresult: bool = False, @@ -188,8 +188,8 @@ def __call__( wrapper: bool = ..., ) -> _F: ... - @overload # noqa: F811 - def __call__( # noqa: F811 + @overload + def __call__( self, function: None = ..., hookwrapper: bool = ..., @@ -200,7 +200,7 @@ def __call__( # noqa: F811 wrapper: bool = ..., ) -> Callable[[_F], _F]: ... - def __call__( # noqa: F811 + def __call__( self, function: _F | None = None, hookwrapper: bool = False, @@ -366,9 +366,7 @@ def varnames( _tail = qualname.rsplit(".", maxsplit=1)[-1] _is_class_method = "." in _tail if args: - if is_bound: - args = args[1:] - elif _is_class_method and args[0] in _IMPLICIT_NAMES: + if is_bound or _is_class_method and args[0] in _IMPLICIT_NAMES: args = args[1:] elif _is_class_method and legacy_noself: if _tail not in _NOSELF_WARN_SUPPRESS: @@ -412,11 +410,11 @@ class HookCaller: """A caller of all registered implementations of a hook specification.""" __slots__ = ( - "name", - "spec", + "_call_history", "_hookexec", "_hookimpls", - "_call_history", + "name", + "spec", ) def __init__( @@ -669,17 +667,17 @@ class HookImpl: """A hook implementation in a :class:`HookCaller`.""" __slots__ = ( - "function", "argnames", + "function", + "hookwrapper", "kwargnames", - "plugin", + "optionalhook", "opts", + "plugin", "plugin_name", - "wrapper", - "hookwrapper", - "optionalhook", "tryfirst", "trylast", + "wrapper", ) def __init__( @@ -725,11 +723,11 @@ def __repr__(self) -> str: @final class HookSpec: __slots__ = ( - "namespace", - "function", - "name", "argnames", + "function", "kwargnames", + "name", + "namespace", "opts", "warn_on_impl", "warn_on_impl_args", diff --git a/src/pluggy/_result.py b/src/pluggy/_result.py index f8020b51..d9d5dbe8 100644 --- a/src/pluggy/_result.py +++ b/src/pluggy/_result.py @@ -26,7 +26,7 @@ class Result(Generic[ResultType]): """An object used to inspect and set the result in a :ref:`hook wrapper `.""" - __slots__ = ("_result", "_exception", "_traceback") + __slots__ = ("_exception", "_result", "_traceback") def __init__( self, diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 7924068a..4c5f95b9 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -441,9 +441,8 @@ def he_method1(self, arg): with pytest.raises(ZeroDivisionError): pm.hook.he_method1(arg="works") - with pytest.raises(HookCallError): - with pytest.warns(UserWarning): - pm.hook.he_method1() + with pytest.raises(HookCallError), pytest.warns(UserWarning): + pm.hook.he_method1() def test_subset_hook_caller(pm: PluginManager) -> None: diff --git a/testing/test_warnings.py b/testing/test_warnings.py index b84cdca6..0bee1549 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -40,12 +40,14 @@ def my_hook(self): pm.register(Plugin1(), "plugin1") pm.register(Plugin2(), "plugin2") pm.register(Plugin3(), "plugin3") - with pytest.warns( - PluggyTeardownRaisedWarning, - match=r"\bplugin2\b.*\bmy_hook\b.*\n.*ZeroDivisionError", - ) as wc: - with pytest.raises(ZeroDivisionError): - pm.hook.my_hook() + with ( + pytest.warns( + PluggyTeardownRaisedWarning, + match=r"\bplugin2\b.*\bmy_hook\b.*\n.*ZeroDivisionError", + ) as wc, + pytest.raises(ZeroDivisionError), + ): + pm.hook.my_hook() assert len(wc.list) == 1 assert Path(wc.list[0].filename).name == "test_warnings.py"