Skip to content

Commit 091d5ea

Browse files
fix casts
1 parent e412a60 commit 091d5ea

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/pluggy/_callers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _multicall(
117117
# If this cast is not valid, a type error is raised below,
118118
# which is the desired response.
119119
res = hook_impl.function(*args)
120-
function_gen = cast(Generator[None, object, object], res)
120+
function_gen = cast("Generator[None, object, object]", res)
121121
next(function_gen) # first yield
122122
teardowns.append(function_gen)
123123
except StopIteration:

src/pluggy/_hooks.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
from ._result import Result
3737

38-
3938
_T = TypeVar("_T")
4039
_F = TypeVar("_F", bound=Callable[..., object])
4140
_Namespace = Union[ModuleType, type]
@@ -46,7 +45,6 @@
4645
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
4746
_CallHistory = List[Tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
4847

49-
5048
class HookspecOpts(TypedDict):
5149
"""Options for a hook specification."""
5250

@@ -62,7 +60,6 @@ class HookspecOpts(TypedDict):
6260
#: .. versionadded:: 1.5
6361
warn_on_impl_args: Mapping[str, Warning] | None
6462

65-
6663
class HookimplOpts(TypedDict):
6764
"""Options for a hook implementation."""
6865

@@ -84,11 +81,11 @@ class HookimplOpts(TypedDict):
8481
specname: str | None
8582

8683
else:
84+
8785
def final(func: _F) -> _F:
8886
return func
89-
overload = final
90-
9187

88+
overload = final
9289

9390

9491
@final
@@ -388,6 +385,7 @@ def __init__(self) -> None:
388385

389386
def __getattr__(self, name: str) -> HookCaller: ...
390387

388+
_CallHistory = List[Tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
391389

392390
# Historical name (pluggy<=1.2), kept for backward compatibility.
393391
_HookRelay = HookRelay

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)