Skip to content

Commit

Permalink
Rename _Hook{Spec,Impl}Opts -> Hook{Spec,Impl}Opts, export from pluggy
Browse files Browse the repository at this point in the history
For typing purposes, refs #428.
  • Loading branch information
bluetech committed Aug 5, 2023
1 parent 9a9e3c2 commit 04e9a9b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
11 changes: 10 additions & 1 deletion src/pluggy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"PluginValidationError",
"HookCaller",
"HookCallError",
"HookSpecOpts",
"HookImplOpts",
"HookRelay",
"HookspecMarker",
"HookimplMarker",
Expand All @@ -18,4 +20,11 @@

from ._manager import PluginManager, PluginValidationError
from ._result import HookCallError, Result
from ._hooks import HookspecMarker, HookimplMarker, HookCaller, HookRelay
from ._hooks import (
HookspecMarker,
HookimplMarker,
HookCaller,
HookRelay,
HookSpecOpts,
HookImplOpts,
)
20 changes: 10 additions & 10 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]


class _HookSpecOpts(TypedDict):
class HookSpecOpts(TypedDict):
"""Options for a hook specification."""

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


class _HookImplOpts(TypedDict):
class HookImplOpts(TypedDict):
"""Options for a hook implementation."""

#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
Expand Down Expand Up @@ -132,7 +132,7 @@ def __call__( # noqa: F811
def setattr_hookspec_opts(func: _F) -> _F:
if historic and firstresult:
raise ValueError("cannot have a historic firstresult hook")
opts: _HookSpecOpts = {
opts: HookSpecOpts = {
"firstresult": firstresult,
"historic": historic,
"warn_on_impl": warn_on_impl,
Expand Down Expand Up @@ -247,7 +247,7 @@ def __call__( # noqa: F811
"""

def setattr_hookimpl_opts(func: _F) -> _F:
opts: _HookImplOpts = {
opts: HookImplOpts = {
"wrapper": wrapper,
"hookwrapper": hookwrapper,
"optionalhook": optionalhook,
Expand All @@ -264,7 +264,7 @@ def setattr_hookimpl_opts(func: _F) -> _F:
return setattr_hookimpl_opts(function)


def normalize_hookimpl_opts(opts: _HookImplOpts) -> None:
def normalize_hookimpl_opts(opts: HookImplOpts) -> None:
opts.setdefault("tryfirst", False)
opts.setdefault("trylast", False)
opts.setdefault("wrapper", False)
Expand Down Expand Up @@ -379,7 +379,7 @@ def __init__(
name: str,
hook_execute: _HookExec,
specmodule_or_class: _Namespace | None = None,
spec_opts: _HookSpecOpts | None = None,
spec_opts: HookSpecOpts | None = None,
) -> None:
""":meta private:"""
self.name: Final = name
Expand All @@ -399,7 +399,7 @@ def has_spec(self) -> bool:
def set_specification(
self,
specmodule_or_class: _Namespace,
spec_opts: _HookSpecOpts,
spec_opts: HookSpecOpts,
) -> None:
if self.spec is not None:
raise ValueError(
Expand Down Expand Up @@ -522,7 +522,7 @@ def call_extra(
not self.is_historic()
), "Cannot directly call a historic hook - use call_historic instead."
self._verify_all_args_are_provided(kwargs)
opts: _HookImplOpts = {
opts: HookImplOpts = {
"wrapper": False,
"hookwrapper": False,
"optionalhook": False,
Expand Down Expand Up @@ -626,7 +626,7 @@ def __init__(
plugin: _Plugin,
plugin_name: str,
function: _HookImplFunction[object],
hook_impl_opts: _HookImplOpts,
hook_impl_opts: HookImplOpts,
) -> None:
self.function: Final = function
self.argnames, self.kwargnames = varnames(self.function)
Expand Down Expand Up @@ -654,7 +654,7 @@ class HookSpec:
"warn_on_impl",
)

def __init__(self, namespace: _Namespace, name: str, opts: _HookSpecOpts) -> None:
def __init__(self, namespace: _Namespace, name: str, opts: HookSpecOpts) -> None:
self.namespace = namespace
self.function: Callable[..., object] = getattr(namespace, name)
self.name = name
Expand Down
12 changes: 6 additions & 6 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
from . import _tracing
from ._callers import _multicall
from ._hooks import _HookImplFunction
from ._hooks import _HookImplOpts
from ._hooks import _HookSpecOpts
from ._hooks import _Namespace
from ._hooks import _Plugin
from ._hooks import _SubsetHookCaller
from ._hooks import HookCaller
from ._hooks import HookImpl
from ._hooks import HookImplOpts
from ._hooks import HookRelay
from ._hooks import HookSpec
from ._hooks import HookSpecOpts
from ._hooks import normalize_hookimpl_opts
from ._result import Result

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

def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> _HookImplOpts | None:
def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> HookImplOpts | None:
"""Try to obtain a hook implementation from an item with the given name
in the given plugin which is being searched for hook impls.

Check warning on line 171 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L170-L171

Added lines #L170 - L171 were not covered by tests
Expand All @@ -181,7 +181,7 @@ def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> _HookImplOpts | Non
if not inspect.isroutine(method):
return None
try:
res: _HookImplOpts | None = getattr(
res: HookImplOpts | None = getattr(
method, self.project_name + "_impl", None
)
except Exception:
Expand Down Expand Up @@ -260,7 +260,7 @@ def add_hookspecs(self, module_or_class: _Namespace) -> None:

def parse_hookspec_opts(
self, module_or_class: _Namespace, name: str
) -> _HookSpecOpts | None:
) -> HookSpecOpts | None:
"""Try to obtain a hook specification from an item with the given name

Check warning on line 264 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L264

Added line #L264 was not covered by tests
in the given module or class which is being searched for hook specs.

Check warning on line 266 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L266

Added line #L266 was not covered by tests
Expand All @@ -273,7 +273,7 @@ def parse_hookspec_opts(
options for items decorated with :class:`HookspecMarker`.
"""

Check warning on line 274 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L274

Added line #L274 was not covered by tests
method: HookSpec = getattr(module_or_class, name)
opts: _HookSpecOpts | None = getattr(method, self.project_name + "_spec", None)
opts: HookSpecOpts | None = getattr(method, self.project_name + "_spec", None)
return opts

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

0 comments on commit 04e9a9b

Please sign in to comment.