Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
18 changes: 9 additions & 9 deletions src/pluggy/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pluggy/_callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
38 changes: 18 additions & 20 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand All @@ -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,
Expand Down Expand Up @@ -188,8 +188,8 @@ def __call__(
wrapper: bool = ...,
) -> _F: ...

@overload # noqa: F811
def __call__( # noqa: F811
@overload
def __call__(
self,
function: None = ...,
hookwrapper: bool = ...,
Expand All @@ -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,
Expand Down Expand Up @@ -366,9 +366,7 @@ def varnames(
_tail = qualname.rsplit("<locals>.", 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:
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/pluggy/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Result(Generic[ResultType]):
"""An object used to inspect and set the result in a :ref:`hook wrapper
<hookwrappers>`."""

__slots__ = ("_result", "_exception", "_traceback")
__slots__ = ("_exception", "_result", "_traceback")

def __init__(
self,
Expand Down
5 changes: 2 additions & 3 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions testing/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down