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

faster baseline import #445

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix casts
  • Loading branch information
RonnyPfannschmidt committed Nov 3, 2024
commit 987ecfd17e1a9a5da514177d60bf97e1ff0222c0
8 changes: 6 additions & 2 deletions src/pluggy/_callers.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@
Tuple[Generator[None, Result[object], None], HookImpl],
Generator[None, object, object],
]
else:

def cast(t, v):
return v

from ._hooks import HookImpl
from ._result import HookCallError
@@ -94,7 +98,7 @@ def _multicall(
# If this cast is not valid, a type error is raised below,
# which is the desired response.
res = hook_impl.function(*args)
wrapper_gen = cast(Generator[None, Result[object], None], res)
wrapper_gen = cast("Generator[None, Result[object], None]", res)
next(wrapper_gen) # first yield
teardowns.append((wrapper_gen, hook_impl))
except StopIteration:
@@ -104,7 +108,7 @@ def _multicall(
# If this cast is not valid, a type error is raised below,
# which is the desired response.
res = hook_impl.function(*args)
function_gen = cast(Generator[None, object, object], res)
function_gen = cast("Generator[None, object, object]", res)
next(function_gen) # first yield
teardowns.append(function_gen)
except StopIteration:
9 changes: 3 additions & 6 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@

from ._result import Result


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


class HookspecOpts(TypedDict):
"""Options for a hook specification."""

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


class HookimplOpts(TypedDict):
"""Options for a hook implementation."""

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

else:

def final(func: _F) -> _F:
return func
overload = final


overload = final


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

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

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

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


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


class HookCaller:
11 changes: 8 additions & 3 deletions src/pluggy/_result.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"""

from __future__ import annotations

TYPE_CHECKING = False
if TYPE_CHECKING:
from types import TracebackType
@@ -16,16 +17,20 @@
from typing import Type
from typing import TypeVar


_ExcInfo = Tuple[Type[BaseException], BaseException, Optional[TracebackType]]
ResultType = TypeVar("ResultType")
else:
from ._hooks import final

def cast(v, t):
return t

class Generic:
"""fake generic"""
def __class_getitem__(cls, key)-> type[object]:

def __class_getitem__(cls, key) -> type[object]:
return object

ResultType = "ResultType"


@@ -110,7 +115,7 @@ def get_result(self) -> ResultType:
exc = self._exception
tb = self._traceback
if exc is None:
return cast(ResultType, self._result)
return cast("ResultType", self._result)
else:
raise exc.with_traceback(tb)