Skip to content

Commit

Permalink
WIP: get pytest importable again
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Sep 3, 2024
1 parent fc17de2 commit 0267624
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 42 deletions.
16 changes: 14 additions & 2 deletions src/pluggy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@
from ._hooks import HookCaller
from ._hooks import HookImpl
from ._hooks import HookimplMarker
from ._hooks import HookimplOpts
from ._hooks import HookRelay
from ._hooks import HookspecMarker
from ._hooks import HookspecOpts
from ._manager import PluginManager
from ._manager import PluginValidationError
from ._result import HookCallError
from ._result import Result
from ._warnings import PluggyTeardownRaisedWarning
from ._warnings import PluggyWarning


TYPE_CHECKING = False
if TYPE_CHECKING:
from ._types import HookimplOpts
from ._types import HookspecOpts
else:

def __getattr__(name: str) -> object:
if name.endswith("Opts"):
from . import _types

return getattr(_types, name)
raise AttributeError(name)
40 changes: 2 additions & 38 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from typing import Sequence
from typing import Tuple
from typing import TYPE_CHECKING
from typing import TypedDict
from typing import TypeVar
from typing import Union

Expand All @@ -42,41 +41,8 @@
_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."""

#: Whether the hook is :ref:`first result only <firstresult>`.
firstresult: bool
#: Whether the hook is :ref:`historic <historic>`.
historic: bool
#: Whether the hook :ref:`warns when implemented <warn_on_impl>`.
warn_on_impl: Warning | None
#: Whether the hook warns when :ref:`certain arguments are requested
#: <warn_on_impl>`.
#:
#: .. versionadded:: 1.5
warn_on_impl_args: Mapping[str, Warning] | None

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

#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
wrapper: bool
#: Whether the hook implementation is an :ref:`old-style wrapper
#: <old_style_hookwrappers>`.
hookwrapper: bool
#: Whether validation against a hook specification is :ref:`optional
#: <optionalhook>`.
optionalhook: bool
#: Whether to try to order this hook implementation :ref:`first
#: <callorder>`.
tryfirst: bool
#: Whether to try to order this hook implementation :ref:`last
#: <callorder>`.
trylast: bool
#: The name of the hook specification to match, see :ref:`specname`.
specname: str | None

from ._types import HookimplOpts
from ._types import HookspecOpts
else:

def final(func: _F) -> _F:
Expand Down Expand Up @@ -382,8 +348,6 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

from ._hooks import _HookImplFunction
from ._hooks import _Namespace
from ._hooks import HookimplOpts
from ._hooks import HookspecOpts
from ._importlib_metadata import DistFacade
from ._types import HookimplOpts
from ._types import HookspecOpts

_BeforeTrace: TypeAlias = "Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]"
_AfterTrace: TypeAlias = (
Expand Down
43 changes: 43 additions & 0 deletions src/pluggy/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Mapping
from typing import TypedDict
import warnings


warnings.warn(ImportWarning(f"{__name__} imported outside of type checking"))


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

#: Whether the hook is :ref:`first result only <firstresult>`.
firstresult: bool
#: Whether the hook is :ref:`historic <historic>`.
historic: bool
#: Whether the hook :ref:`warns when implemented <warn_on_impl>`.
warn_on_impl: Warning | None
#: Whether the hook warns when :ref:`certain arguments are requested
#: <warn_on_impl>`.
#:
#: .. versionadded:: 1.5
warn_on_impl_args: Mapping[str, Warning] | None


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

#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
wrapper: bool
#: Whether the hook implementation is an :ref:`old-style wrapper
#: <old_style_hookwrappers>`.
hookwrapper: bool
#: Whether validation against a hook specification is :ref:`optional
#: <optionalhook>`.
optionalhook: bool
#: Whether to try to order this hook implementation :ref:`first
#: <callorder>`.
tryfirst: bool
#: Whether to try to order this hook implementation :ref:`last
#: <callorder>`.
trylast: bool
#: The name of the hook specification to match, see :ref:`specname`.
specname: str | None

0 comments on commit 0267624

Please sign in to comment.