Skip to content

Commit 739fcd4

Browse files
committed
Export HookImpl as pluggy.HookImpl
Used in hook monitoring and in `pm.hook.my_hook.get_hookimpls()`. Refs #428.
1 parent de915b0 commit 739fcd4

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

docs/api_reference.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ API Reference
3535
:show-inheritance:
3636
:members:
3737

38+
.. autoclass:: pluggy.HookImpl()
39+
:members:
40+
3841
.. autoclass:: pluggy.HookspecOpts()
3942
:show-inheritance:
4043
:members:

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,11 @@ The expected signature and default implementations for these functions is:
966966

967967
.. code-block:: python
968968
969-
def before(hook_name, methods, kwargs):
969+
def before(hook_name, hook_impls, kwargs):
970970
pass
971971
972972
973-
def after(outcome, hook_name, methods, kwargs):
973+
def after(outcome, hook_name, hook_impls, kwargs):
974974
pass
975975
976976
Public API

src/pluggy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"HookCallError",
1313
"HookspecOpts",
1414
"HookimplOpts",
15+
"HookImpl",
1516
"HookRelay",
1617
"HookspecMarker",
1718
"HookimplMarker",
@@ -27,4 +28,5 @@
2728
HookRelay,
2829
HookspecOpts,
2930
HookimplOpts,
31+
HookImpl,
3032
)

src/pluggy/_hooks.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ def __repr__(self) -> str:
607607

608608

609609
class HookImpl:
610+
"""A hook implementation in a :class:`HookCaller`."""
611+
610612
__slots__ = (
611613
"function",
612614
"argnames",
@@ -628,15 +630,33 @@ def __init__(
628630
function: _HookImplFunction[object],
629631
hook_impl_opts: HookimplOpts,
630632
) -> None:
633+
""":meta private:"""
634+
#: The hook implementation function.
631635
self.function: Final = function
632-
self.argnames, self.kwargnames = varnames(self.function)
636+
argnames, kwargnames = varnames(self.function)
637+
#: The positional parameter names of ``function```.
638+
self.argnames = argnames
639+
#: The keyword parameter names of ``function```.
640+
self.kwargnames = kwargnames
641+
#: The plugin which defined this hook implementation.
633642
self.plugin = plugin
643+
#: The :class:`HookimplOpts` used to configure this hook implementation.
634644
self.opts = hook_impl_opts
645+
#: The name of the plugin which defined this hook implementation.
635646
self.plugin_name = plugin_name
647+
#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
636648
self.wrapper = hook_impl_opts["wrapper"]
649+
#: Whether the hook implementation is an :ref:`old-style wrapper
650+
#: <old_style_hookwrappers>`.
637651
self.hookwrapper = hook_impl_opts["hookwrapper"]
652+
#: Whether validation against a hook specification is :ref:`optional
653+
#: <optionalhook>`.
638654
self.optionalhook = hook_impl_opts["optionalhook"]
655+
#: Whether to try to order this hook implementation :ref:`first
656+
#: <callorder>`.
639657
self.tryfirst = hook_impl_opts["tryfirst"]
658+
#: Whether to try to order this hook implementation :ref:`last
659+
#: <callorder>`.
640660
self.trylast = hook_impl_opts["trylast"]
641661

642662
def __repr__(self) -> str:

0 commit comments

Comments
 (0)