Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stubs for pluggy==1.2.0 #10473

Merged
merged 15 commits into from
Jul 20, 2023
Merged
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
1 change: 1 addition & 0 deletions stubs/pluggy/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pluggy._hooks._HookRelay.__getattr__ # is not present at runtime
1 change: 1 addition & 0 deletions stubs/pluggy/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.2.0"
5 changes: 5 additions & 0 deletions stubs/pluggy/pluggy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ._hooks import HookimplMarker as HookimplMarker, HookspecMarker as HookspecMarker
from ._manager import PluginManager as PluginManager, PluginValidationError as PluginValidationError
from ._result import HookCallError as HookCallError
hoefling marked this conversation as resolved.
Show resolved Hide resolved

__version__: str
116 changes: 116 additions & 0 deletions stubs/pluggy/pluggy/_hooks.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from collections.abc import Callable, Generator, Mapping, Sequence
from types import ModuleType
from typing import Any, TypeVar, overload
from typing_extensions import TypeAlias, TypedDict

from ._result import _Result

_T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., object])
_Namespace: TypeAlias = ModuleType | type
_Plugin: TypeAlias = object
_HookExec: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, object], bool], object | list[object]]
_HookImplFunction: TypeAlias = Callable[..., _T | Generator[None, _Result[_T], None]]

class _HookSpecOpts(TypedDict):
firstresult: bool
historic: bool
warn_on_impl: Warning | None

class _HookImplOpts(TypedDict):
wrapper: bool
hookwrapper: bool
optionalhook: bool
tryfirst: bool
trylast: bool
specname: str | None

class HookspecMarker:
project_name: str
def __init__(self, project_name: str) -> None: ...
@overload
def __call__(
self, function: _F, firstresult: bool = False, historic: bool = False, warn_on_impl: Warning | None = None
) -> _F: ...
@overload
def __call__(
self, function: None = None, firstresult: bool = False, historic: bool = False, warn_on_impl: Warning | None = None
) -> Callable[[_F], _F]: ...

class HookimplMarker:
project_name: str
def __init__(self, project_name: str) -> None: ...
@overload
def __call__(
self,
function: _F,
hookwrapper: bool = False,
optionalhook: bool = False,
tryfirst: bool = False,
trylast: bool = False,
specname: str | None = None,
wrapper: bool = False,
) -> _F: ...
@overload
def __call__(
self,
function: None = None,
hookwrapper: bool = False,
optionalhook: bool = False,
tryfirst: bool = False,
trylast: bool = False,
specname: str | None = None,
wrapper: bool = False,
) -> Callable[[_F], _F]: ...

def normalize_hookimpl_opts(opts: _HookImplOpts) -> None: ...
def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]: ...

class _HookRelay:
def __getattr__(self, name: str) -> _HookCaller: ...

class _HookCaller:
name: str
spec: HookSpec | None
def __init__(
self,
name: str,
hook_execute: _HookExec,
specmodule_or_class: _Namespace | None = None,
spec_opts: _HookSpecOpts | None = None,
) -> None: ...
def has_spec(self) -> bool: ...
def set_specification(self, specmodule_or_class: _Namespace, spec_opts: _HookSpecOpts) -> None: ...
def is_historic(self) -> bool: ...
def get_hookimpls(self) -> list[HookImpl]: ...
def __call__(self, **kwargs: object) -> Any: ...
def call_historic(
self, result_callback: Callable[[Any], None] | None = None, kwargs: Mapping[str, object] | None = None
) -> None: ...
def call_extra(self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object]) -> Any: ...

class HookImpl:
function: _HookImplFunction[object]
plugin: _Plugin
opts: _HookImplOpts
plugin_name: str
wrapper: bool
hookwrapper: bool
optionalhook: bool
tryfirst: bool
trylast: bool
argnames: tuple[str, ...]
kwargnames: tuple[str, ...]
def __init__(
self, plugin: _Plugin, plugin_name: str, function: _HookImplFunction[object], hook_impl_opts: _HookImplOpts
) -> None: ...

class HookSpec:
namespace: _Namespace
function: Callable[..., object]
name: str
opts: _HookSpecOpts
warn_on_impl: Warning | None
argnames: tuple[str, ...]
kwargnames: tuple[str, ...]
def __init__(self, namespace: _Namespace, name: str, opts: _HookSpecOpts) -> None: ...
65 changes: 65 additions & 0 deletions stubs/pluggy/pluggy/_manager.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sys
from _typeshed import Incomplete
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import Any
from typing_extensions import TypeAlias

from ._hooks import (
HookImpl as HookImpl,
HookSpec as HookSpec,
_HookCaller,
_HookImplOpts,
_HookRelay,
_HookSpecOpts,
_Namespace,
_Plugin,
normalize_hookimpl_opts as normalize_hookimpl_opts,
)
from ._result import _Result as _Result
from ._tracing import TagTracerSub

if sys.version_info >= (3, 8):
from importlib.metadata import Distribution
else:
Distribution: TypeAlias = Any
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

_BeforeTrace: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
_AfterTrace: TypeAlias = Callable[[_Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None]

class PluginValidationError(Exception):
plugin: _Plugin
def __init__(self, plugin: _Plugin, message: str) -> None: ...

class DistFacade:
def __init__(self, dist: Distribution) -> None: ...
@property
def project_name(self) -> str: ...
def __getattr__(self, attr: str, default: Incomplete | None = None) -> Any: ...
def __dir__(self) -> list[str]: ...

class PluginManager:
project_name: str
trace: TagTracerSub
hook: _HookRelay
def __init__(self, project_name: str) -> None: ...
def register(self, plugin: _Plugin, name: str | None = None) -> str | None: ...
def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> _HookImplOpts | None: ...
def unregister(self, plugin: _Plugin | None = None, name: str | None = None) -> _Plugin: ...
def set_blocked(self, name: str) -> None: ...
def is_blocked(self, name: str) -> bool: ...
def add_hookspecs(self, module_or_class: _Namespace) -> None: ...
def parse_hookspec_opts(self, module_or_class: _Namespace, name: str) -> _HookSpecOpts | None: ...
def get_plugins(self) -> set[Any]: ...
def is_registered(self, plugin: _Plugin) -> bool: ...
def get_canonical_name(self, plugin: _Plugin) -> str: ...
def get_plugin(self, name: str) -> Any | None: ...
def has_plugin(self, name: str) -> bool: ...
def get_name(self, plugin: _Plugin) -> str | None: ...
def check_pending(self) -> None: ...
def load_setuptools_entrypoints(self, group: str, name: str | None = None) -> int: ...
def list_plugin_distinfo(self) -> list[tuple[_Plugin, DistFacade]]: ...
def list_name_plugin(self) -> list[tuple[str, _Plugin]]: ...
def get_hookcallers(self, plugin: _Plugin) -> list[_HookCaller] | None: ...
def add_hookcall_monitoring(self, before: _BeforeTrace, after: _AfterTrace) -> Callable[[], None]: ...
def enable_tracing(self) -> Callable[[], None]: ...
def subset_hook_caller(self, name: str, remove_plugins: Iterable[_Plugin]) -> _HookCaller: ...
19 changes: 19 additions & 0 deletions stubs/pluggy/pluggy/_result.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from _typeshed import ExcInfo
from collections.abc import Callable
from typing import Generic, TypeVar

_T = TypeVar("_T")

class HookCallError(Exception): ...

class _Result(Generic[_T]):
def __init__(self, result: _T | None, exception: BaseException | None) -> None: ...
@property
def excinfo(self) -> ExcInfo | None: ...
@property
def exception(self) -> BaseException | None: ...
@classmethod
def from_call(cls, func: Callable[[], _T]) -> _Result[_T]: ...
def force_result(self, result: _T) -> None: ...
def force_exception(self, exception: BaseException) -> None: ...
def get_result(self) -> _T: ...
20 changes: 20 additions & 0 deletions stubs/pluggy/pluggy/_tracing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from collections.abc import Callable
from typing import Any
from typing_extensions import TypeAlias

_Writer: TypeAlias = Callable[[str], object]
_Processor: TypeAlias = Callable[[tuple[str, ...], tuple[Any, ...]], None]

class TagTracer:
indent: int
def __init__(self) -> None: ...
def get(self, name: str) -> TagTracerSub: ...
def setwriter(self, writer: _Writer | None) -> None: ...
def setprocessor(self, tags: str | tuple[str, ...], processor: _Processor) -> None: ...

class TagTracerSub:
root: TagTracer
tags: tuple[str, ...]
def __init__(self, root: TagTracer, tags: tuple[str, ...]) -> None: ...
def __call__(self, *args: object) -> None: ...
def get(self, name: str) -> TagTracerSub: ...