Skip to content

Commit 78fe2e9

Browse files
Add TypeAlias annotations for improved type clarity
Leverage TypeAlias (available in Python 3.10+) to explicitly mark type aliases throughout the codebase: - _hooks.py: _Namespace, _Plugin, _HookExec, _HookImplFunction, _CallHistory - _manager.py: _BeforeTrace, _AfterTrace - _result.py: _ExcInfo - _callers.py: Teardown This improves IDE support, type checker accuracy, and makes the distinction between type aliases and regular assignments clear. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f68db34 commit 78fe2e9

File tree

5 files changed

+18
-95
lines changed

5 files changed

+18
-95
lines changed

src/pluggy/_callers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections.abc import Sequence
1010
from typing import cast
1111
from typing import NoReturn
12+
from typing import TypeAlias
1213
import warnings
1314

1415
from ._hooks import HookImpl
@@ -19,7 +20,7 @@
1920

2021
# Need to distinguish between old- and new-style hook wrappers.
2122
# Wrapping with a tuple is the fastest type-safe way I found to do it.
22-
Teardown = Generator[None, object, object]
23+
Teardown: TypeAlias = Generator[None, object, object]
2324

2425

2526
def run_old_style_hookwrapper(

src/pluggy/_hooks.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import final
1818
from typing import overload
1919
from typing import TYPE_CHECKING
20+
from typing import TypeAlias
2021
from typing import TypedDict
2122
from typing import TypeVar
2223
import warnings
@@ -26,13 +27,14 @@
2627

2728
_T = TypeVar("_T")
2829
_F = TypeVar("_F", bound=Callable[..., object])
29-
_Namespace = ModuleType | type
30-
_Plugin = object
31-
_HookExec = Callable[
30+
31+
_Namespace: TypeAlias = ModuleType | type
32+
_Plugin: TypeAlias = object
33+
_HookExec: TypeAlias = Callable[
3234
[str, Sequence["HookImpl"], Mapping[str, object], bool],
3335
object | list[object],
3436
]
35-
_HookImplFunction = Callable[..., _T | Generator[None, Result[_T], None]]
37+
_HookImplFunction: TypeAlias = Callable[..., _T | Generator[None, Result[_T], None]]
3638

3739

3840
class HookspecOpts(TypedDict):
@@ -372,7 +374,9 @@ def __getattr__(self, name: str) -> HookCaller: ...
372374
_HookRelay = HookRelay
373375

374376

375-
_CallHistory = list[tuple[Mapping[str, object], Callable[[Any], None] | None]]
377+
_CallHistory: TypeAlias = list[
378+
tuple[Mapping[str, object], Callable[[Any], None] | None]
379+
]
376380

377381

378382
class HookCaller:

src/pluggy/_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import cast
1111
from typing import Final
1212
from typing import TYPE_CHECKING
13+
from typing import TypeAlias
1314
import warnings
1415

1516
from . import _tracing
@@ -32,8 +33,10 @@
3233
import importlib.metadata
3334

3435

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

3841

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

src/pluggy/_result.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from typing import cast
1010
from typing import final
1111
from typing import Generic
12+
from typing import TypeAlias
1213
from typing import TypeVar
1314

1415

15-
_ExcInfo = tuple[type[BaseException], BaseException, TracebackType | None]
16+
_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None]
1617
ResultType = TypeVar("ResultType")
1718

1819

uv.lock

Lines changed: 0 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)