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 1, 2024
1 parent f087cee commit 85197cb
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


Check warning on line 37 in src/pluggy/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/__init__.py#L36-L37

Added lines #L36 - L37 were not covered by tests
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

Check warning on line 26 in src/pluggy/_hooks.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_hooks.py#L15-L26

Added lines #L15 - L26 were not covered by tests
from typing import Tuple
from typing import TYPE_CHECKING

Check warning on line 28 in src/pluggy/_hooks.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_hooks.py#L28

Added line #L28 was not covered by tests
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]]]]

Check warning on line 42 in src/pluggy/_hooks.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_hooks.py#L42

Added line #L42 was not covered by tests

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:

Check warning on line 46 in src/pluggy/_hooks.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_hooks.py#L46

Added line #L46 was not covered by tests

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 @@

Check warning on line 27 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L19-L27

Added lines #L19 - L27 were not covered by tests
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 85197cb

Please sign in to comment.