Skip to content

Commit 252ce2c

Browse files
pass tests initial
1 parent ba63ac1 commit 252ce2c

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
requires = [
33
"setuptools>=65.0",
44
"setuptools-scm[toml]>=8.0",
5+
"mypy>=1.15",
56
]
67
build-backend = "setuptools.build_meta"
78

src/pluggy/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"HookspecOpts",
88
"HookimplOpts",
99
"HookImpl",
10-
"HookRelay",
1110
"HookspecMarker",
1211
"HookimplMarker",
1312
"Result",
@@ -18,7 +17,7 @@
1817
from ._hooks import HookImpl
1918
from ._hooks import HookimplMarker
2019
from ._hooks import HookimplOpts
21-
from ._hooks import HookRelay
20+
from ._hookrelay import HookRelay
2221
from ._hooks import HookspecMarker
2322
from ._hooks import HookspecOpts
2423
from ._manager import PluginManager

src/pluggy/_hookrelay.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
separate module for only hookrelay as mypyc doesnt support dynamic attributes/getattr
3+
"""
4+
5+
from __future__ import annotations
6+
7+
from typing import final, TYPE_CHECKING
8+
9+
if TYPE_CHECKING:
10+
from pluggy import HookCaller
11+
12+
13+
@final
14+
class HookRelay:
15+
"""Hook holder object for performing 1:N hook calls where N is the number
16+
of registered plugins."""
17+
18+
__slots__ = ("__dict__",)
19+
20+
def __init__(self) -> None:
21+
""":meta private:"""
22+
23+
if TYPE_CHECKING:
24+
25+
def __getattr__(self, name: str) -> HookCaller: ...

src/pluggy/_hooks.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,26 @@
1717
from typing import final
1818
from typing import Optional
1919
from typing import overload
20-
from typing import TYPE_CHECKING
2120
from typing import TypedDict
2221
from typing import TypeVar
2322
from typing import Union
2423
import warnings
2524

25+
from ._hookrelay import HookRelay
2626
from ._result import Result
2727

2828

2929
_T = TypeVar("_T")
3030
_F = TypeVar("_F", bound=Callable[..., object])
3131
_Namespace = Union[ModuleType, type]
3232
_Plugin = object
33-
_HookExec = Callable[
34-
[str, Sequence["HookImpl"], Mapping[str, object], bool],
35-
Union[object, list[object]],
33+
34+
type _HookExec = Callable[
35+
[str, Sequence[HookImpl], Mapping[str, object], bool],
36+
Union[object, list[object]]
3637
]
37-
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
38+
39+
type _HookImplFunction[T] = Callable[..., Union[T, Generator[None, Result[T], None]]]
3840

3941

4042
class HookspecOpts(TypedDict):
@@ -355,21 +357,6 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
355357
return args, kwargs
356358

357359

358-
@final
359-
class HookRelay:
360-
"""Hook holder object for performing 1:N hook calls where N is the number
361-
of registered plugins."""
362-
363-
__slots__ = ("__dict__",)
364-
365-
def __init__(self) -> None:
366-
""":meta private:"""
367-
368-
if TYPE_CHECKING:
369-
370-
def __getattr__(self, name: str) -> HookCaller: ...
371-
372-
373360
# Historical name (pluggy<=1.2), kept for backward compatibility.
374361
_HookRelay = HookRelay
375362

@@ -388,6 +375,8 @@ class HookCaller:
388375
"_call_history",
389376
)
390377

378+
379+
_call_history: _CallHistory | None
391380
def __init__(
392381
self,
393382
name: str,
@@ -407,7 +396,7 @@ def __init__(
407396
# 5. wrappers
408397
# 6. tryfirst wrappers
409398
self._hookimpls: Final[list[HookImpl]] = []
410-
self._call_history: _CallHistory | None = None
399+
self._call_history = None
411400
# TODO: Document, or make private.
412401
self.spec: HookSpec | None = None
413402
if specmodule_or_class is not None:

src/pluggy/_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
from collections.abc import Sequence
66
import inspect
77
import types
8-
from typing import Any
8+
from typing import Any, TypeAlias
99
from typing import Callable
1010
from typing import cast
1111
from typing import Final
1212
from typing import TYPE_CHECKING
1313
import warnings
1414

1515
from . import _tracing
16+
from ._hookrelay import HookRelay
1617
from ._callers import _multicall
1718
from ._hooks import _HookImplFunction
1819
from ._hooks import _Namespace
@@ -21,7 +22,6 @@
2122
from ._hooks import HookCaller
2223
from ._hooks import HookImpl
2324
from ._hooks import HookimplOpts
24-
from ._hooks import HookRelay
2525
from ._hooks import HookspecOpts
2626
from ._hooks import normalize_hookimpl_opts
2727
from ._result import Result
@@ -32,8 +32,8 @@
3232
import importlib.metadata
3333

3434

35-
_BeforeTrace = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
36-
_AfterTrace = Callable[[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None]
35+
_BeforeTrace: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
36+
_AfterTrace: TypeAlias = Callable[[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None]
3737

3838

3939
def _warn_for_function(warning: Warning, function: Callable[..., object]) -> None:

0 commit comments

Comments
 (0)