Skip to content

Commit 987ecfd

Browse files
fix casts
1 parent 24f5da0 commit 987ecfd

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/pluggy/_callers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
Tuple[Generator[None, Result[object], None], HookImpl],
2929
Generator[None, object, object],
3030
]
31+
else:
32+
33+
def cast(t, v):
34+
return v
3135

3236
from ._hooks import HookImpl
3337
from ._result import HookCallError
@@ -94,7 +98,7 @@ def _multicall(
9498
# If this cast is not valid, a type error is raised below,
9599
# which is the desired response.
96100
res = hook_impl.function(*args)
97-
wrapper_gen = cast(Generator[None, Result[object], None], res)
101+
wrapper_gen = cast("Generator[None, Result[object], None]", res)
98102
next(wrapper_gen) # first yield
99103
teardowns.append((wrapper_gen, hook_impl))
100104
except StopIteration:
@@ -104,7 +108,7 @@ def _multicall(
104108
# If this cast is not valid, a type error is raised below,
105109
# which is the desired response.
106110
res = hook_impl.function(*args)
107-
function_gen = cast(Generator[None, object, object], res)
111+
function_gen = cast("Generator[None, object, object]", res)
108112
next(function_gen) # first yield
109113
teardowns.append(function_gen)
110114
except StopIteration:

src/pluggy/_hooks.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
from ._result import Result
3333

34-
3534
_T = TypeVar("_T")
3635
_F = TypeVar("_F", bound=Callable[..., object])
3736
_Namespace = Union[ModuleType, type]
@@ -42,7 +41,6 @@
4241
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
4342
_CallHistory = List[Tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
4443

45-
4644
class HookspecOpts(TypedDict):
4745
"""Options for a hook specification."""
4846

@@ -58,7 +56,6 @@ class HookspecOpts(TypedDict):
5856
#: .. versionadded:: 1.5
5957
warn_on_impl_args: Mapping[str, Warning] | None
6058

61-
6259
class HookimplOpts(TypedDict):
6360
"""Options for a hook implementation."""
6461

@@ -80,11 +77,11 @@ class HookimplOpts(TypedDict):
8077
specname: str | None
8178

8279
else:
80+
8381
def final(func: _F) -> _F:
8482
return func
85-
overload = final
86-
8783

84+
overload = final
8885

8986

9087
@final
@@ -384,12 +381,12 @@ def __init__(self) -> None:
384381

385382
def __getattr__(self, name: str) -> HookCaller: ...
386383

384+
_CallHistory = List[Tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
387385

388386
# Historical name (pluggy<=1.2), kept for backward compatibility.
389387
_HookRelay = HookRelay
390388

391389

392-
_CallHistory = List[Tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
393390

394391

395392
class HookCaller:

src/pluggy/_result.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from __future__ import annotations
6+
67
TYPE_CHECKING = False
78
if TYPE_CHECKING:
89
from types import TracebackType
@@ -16,16 +17,20 @@
1617
from typing import Type
1718
from typing import TypeVar
1819

19-
2020
_ExcInfo = Tuple[Type[BaseException], BaseException, Optional[TracebackType]]
2121
ResultType = TypeVar("ResultType")
2222
else:
2323
from ._hooks import final
2424

25+
def cast(v, t):
26+
return t
27+
2528
class Generic:
2629
"""fake generic"""
27-
def __class_getitem__(cls, key)-> type[object]:
30+
31+
def __class_getitem__(cls, key) -> type[object]:
2832
return object
33+
2934
ResultType = "ResultType"
3035

3136

@@ -110,7 +115,7 @@ def get_result(self) -> ResultType:
110115
exc = self._exception
111116
tb = self._traceback
112117
if exc is None:
113-
return cast(ResultType, self._result)
118+
return cast("ResultType", self._result)
114119
else:
115120
raise exc.with_traceback(tb)
116121

0 commit comments

Comments
 (0)