Skip to content

Commit 04e9a9b

Browse files
committed
Rename _Hook{Spec,Impl}Opts -> Hook{Spec,Impl}Opts, export from pluggy
For typing purposes, refs #428.
1 parent 9a9e3c2 commit 04e9a9b

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/pluggy/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"PluginValidationError",
1111
"HookCaller",
1212
"HookCallError",
13+
"HookSpecOpts",
14+
"HookImplOpts",
1315
"HookRelay",
1416
"HookspecMarker",
1517
"HookimplMarker",
@@ -18,4 +20,11 @@
1820

1921
from ._manager import PluginManager, PluginValidationError
2022
from ._result import HookCallError, Result
21-
from ._hooks import HookspecMarker, HookimplMarker, HookCaller, HookRelay
23+
from ._hooks import (
24+
HookspecMarker,
25+
HookimplMarker,
26+
HookCaller,
27+
HookRelay,
28+
HookSpecOpts,
29+
HookImplOpts,
30+
)

src/pluggy/_hooks.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
3838

3939

40-
class _HookSpecOpts(TypedDict):
40+
class HookSpecOpts(TypedDict):
4141
"""Options for a hook specification."""
4242

4343
#: Whether the hook is :ref:`first result only <firstresult>`.
@@ -48,7 +48,7 @@ class _HookSpecOpts(TypedDict):
4848
warn_on_impl: Warning | None
4949

5050

51-
class _HookImplOpts(TypedDict):
51+
class HookImplOpts(TypedDict):
5252
"""Options for a hook implementation."""
5353

5454
#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
@@ -132,7 +132,7 @@ def __call__( # noqa: F811
132132
def setattr_hookspec_opts(func: _F) -> _F:
133133
if historic and firstresult:
134134
raise ValueError("cannot have a historic firstresult hook")
135-
opts: _HookSpecOpts = {
135+
opts: HookSpecOpts = {
136136
"firstresult": firstresult,
137137
"historic": historic,
138138
"warn_on_impl": warn_on_impl,
@@ -247,7 +247,7 @@ def __call__( # noqa: F811
247247
"""
248248

249249
def setattr_hookimpl_opts(func: _F) -> _F:
250-
opts: _HookImplOpts = {
250+
opts: HookImplOpts = {
251251
"wrapper": wrapper,
252252
"hookwrapper": hookwrapper,
253253
"optionalhook": optionalhook,
@@ -264,7 +264,7 @@ def setattr_hookimpl_opts(func: _F) -> _F:
264264
return setattr_hookimpl_opts(function)
265265

266266

267-
def normalize_hookimpl_opts(opts: _HookImplOpts) -> None:
267+
def normalize_hookimpl_opts(opts: HookImplOpts) -> None:
268268
opts.setdefault("tryfirst", False)
269269
opts.setdefault("trylast", False)
270270
opts.setdefault("wrapper", False)
@@ -379,7 +379,7 @@ def __init__(
379379
name: str,
380380
hook_execute: _HookExec,
381381
specmodule_or_class: _Namespace | None = None,
382-
spec_opts: _HookSpecOpts | None = None,
382+
spec_opts: HookSpecOpts | None = None,
383383
) -> None:
384384
""":meta private:"""
385385
self.name: Final = name
@@ -399,7 +399,7 @@ def has_spec(self) -> bool:
399399
def set_specification(
400400
self,
401401
specmodule_or_class: _Namespace,
402-
spec_opts: _HookSpecOpts,
402+
spec_opts: HookSpecOpts,
403403
) -> None:
404404
if self.spec is not None:
405405
raise ValueError(
@@ -522,7 +522,7 @@ def call_extra(
522522
not self.is_historic()
523523
), "Cannot directly call a historic hook - use call_historic instead."
524524
self._verify_all_args_are_provided(kwargs)
525-
opts: _HookImplOpts = {
525+
opts: HookImplOpts = {
526526
"wrapper": False,
527527
"hookwrapper": False,
528528
"optionalhook": False,
@@ -626,7 +626,7 @@ def __init__(
626626
plugin: _Plugin,
627627
plugin_name: str,
628628
function: _HookImplFunction[object],
629-
hook_impl_opts: _HookImplOpts,
629+
hook_impl_opts: HookImplOpts,
630630
) -> None:
631631
self.function: Final = function
632632
self.argnames, self.kwargnames = varnames(self.function)
@@ -654,7 +654,7 @@ class HookSpec:
654654
"warn_on_impl",
655655
)
656656

657-
def __init__(self, namespace: _Namespace, name: str, opts: _HookSpecOpts) -> None:
657+
def __init__(self, namespace: _Namespace, name: str, opts: HookSpecOpts) -> None:
658658
self.namespace = namespace
659659
self.function: Callable[..., object] = getattr(namespace, name)
660660
self.name = name

src/pluggy/_manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
from . import _tracing
1616
from ._callers import _multicall
1717
from ._hooks import _HookImplFunction
18-
from ._hooks import _HookImplOpts
19-
from ._hooks import _HookSpecOpts
2018
from ._hooks import _Namespace
2119
from ._hooks import _Plugin
2220
from ._hooks import _SubsetHookCaller
2321
from ._hooks import HookCaller
2422
from ._hooks import HookImpl
23+
from ._hooks import HookImplOpts
2524
from ._hooks import HookRelay
2625
from ._hooks import HookSpec
26+
from ._hooks import HookSpecOpts
2727
from ._hooks import normalize_hookimpl_opts
2828
from ._result import Result
2929

@@ -166,7 +166,7 @@ def register(self, plugin: _Plugin, name: str | None = None) -> str | None:
166166
hook._add_hookimpl(hookimpl)
167167
return plugin_name
168168

169-
def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> _HookImplOpts | None:
169+
def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> HookImplOpts | None:
170170
"""Try to obtain a hook implementation from an item with the given name
171171
in the given plugin which is being searched for hook impls.
172172
@@ -181,7 +181,7 @@ def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> _HookImplOpts | Non
181181
if not inspect.isroutine(method):
182182
return None
183183
try:
184-
res: _HookImplOpts | None = getattr(
184+
res: HookImplOpts | None = getattr(
185185
method, self.project_name + "_impl", None
186186
)
187187
except Exception:
@@ -260,7 +260,7 @@ def add_hookspecs(self, module_or_class: _Namespace) -> None:
260260

261261
def parse_hookspec_opts(
262262
self, module_or_class: _Namespace, name: str
263-
) -> _HookSpecOpts | None:
263+
) -> HookSpecOpts | None:
264264
"""Try to obtain a hook specification from an item with the given name
265265
in the given module or class which is being searched for hook specs.
266266
@@ -273,7 +273,7 @@ def parse_hookspec_opts(
273273
options for items decorated with :class:`HookspecMarker`.
274274
"""
275275
method: HookSpec = getattr(module_or_class, name)
276-
opts: _HookSpecOpts | None = getattr(method, self.project_name + "_spec", None)
276+
opts: HookSpecOpts | None = getattr(method, self.project_name + "_spec", None)
277277
return opts
278278

279279
def get_plugins(self) -> set[Any]:

0 commit comments

Comments
 (0)