|
@@ -1,11 +1,11 @@
|
|
|
"""
|
|
|
Internal hook annotation, representation and calling machinery.
|
|
|
"""
|
|
|
+
|
|
|
from __future__ import annotations
|
|
|
|
|
|
import inspect
|
|
|
import sys
|
|
|
-import warnings
|
|
|
from types import ModuleType
|
|
|
from typing import AbstractSet
|
|
|
from typing import Any
|
|
@@ -23,6 +23,7 @@ from typing import TYPE_CHECKING
|
|
|
from typing import TypedDict
|
|
|
from typing import TypeVar
|
|
|
from typing import Union
|
|
|
+import warnings
|
|
|
|
|
|
from ._result import Result
|
|
|
|
|
@@ -47,6 +48,11 @@ class HookspecOpts(TypedDict):
|
|
|
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):
|
|
@@ -91,8 +97,8 @@ class HookspecMarker:
|
|
|
firstresult: bool = False,
|
|
|
historic: bool = False,
|
|
|
warn_on_impl: Warning | None = None,
|
|
|
- ) -> _F:
|
|
|
- ...
|
|
|
+ warn_on_impl_args: Mapping[str, Warning] | None = None,
|
|
|
+ ) -> _F: ...
|
|
|
|
|
|
@overload # noqa: F811
|
|
|
def __call__( # noqa: F811
|
|
@@ -101,8 +107,8 @@ class HookspecMarker:
|
|
|
firstresult: bool = ...,
|
|
|
historic: bool = ...,
|
|
|
warn_on_impl: Warning | None = ...,
|
|
|
- ) -> Callable[[_F], _F]:
|
|
|
- ...
|
|
|
+ warn_on_impl_args: Mapping[str, Warning] | None = ...,
|
|
|
+ ) -> Callable[[_F], _F]: ...
|
|
|
|
|
|
def __call__( # noqa: F811
|
|
|
self,
|
|
@@ -110,6 +116,7 @@ class HookspecMarker:
|
|
|
firstresult: bool = False,
|
|
|
historic: bool = False,
|
|
|
warn_on_impl: Warning | None = None,
|
|
|
+ warn_on_impl_args: Mapping[str, Warning] | None = None,
|
|
|
) -> _F | Callable[[_F], _F]:
|
|
|
"""If passed a function, directly sets attributes on the function
|
|
|
which will make it discoverable to :meth:`PluginManager.add_hookspecs`.
|
|
@@ -129,6 +136,13 @@ class HookspecMarker:
|
|
|
:param warn_on_impl:
|
|
|
If given, every implementation of this hook will trigger the given
|
|
|
warning. See :ref:`warn_on_impl`.
|
|
|
+
|
|
|
+ :param warn_on_impl_args:
|
|
|
+ If given, every implementation of this hook which requests one of
|
|
|
+ the arguments in the dict will trigger the corresponding warning.
|
|
|
+ See :ref:`warn_on_impl`.
|
|
|
+
|
|
|
+ .. versionadded:: 1.5
|
|
|
"""
|
|
|
|
|
|
def setattr_hookspec_opts(func: _F) -> _F:
|
|
@@ -138,6 +152,7 @@ class HookspecMarker:
|
|
|
"firstresult": firstresult,
|
|
|
"historic": historic,
|
|
|
"warn_on_impl": warn_on_impl,
|
|
|
+ "warn_on_impl_args": warn_on_impl_args,
|
|
|
}
|
|
|
setattr(func, self.project_name + "_spec", opts)
|
|
|
return func
|
|
@@ -172,8 +187,7 @@ class HookimplMarker:
|
|
|
trylast: bool = ...,
|
|
|
specname: str | None = ...,
|
|
|
wrapper: bool = ...,
|
|
|
- ) -> _F:
|
|
|
- ...
|
|
|
+ ) -> _F: ...
|
|
|
|
|
|
@overload # noqa: F811
|
|
|
def __call__( # noqa: F811
|
|
@@ -185,8 +199,7 @@ class HookimplMarker:
|
|
|
trylast: bool = ...,
|
|
|
specname: str | None = ...,
|
|
|
wrapper: bool = ...,
|
|
|
- ) -> Callable[[_F], _F]:
|
|
|
- ...
|
|
|
+ ) -> Callable[[_F], _F]: ...
|
|
|
|
|
|
def __call__( # noqa: F811
|
|
|
self,
|
|
@@ -356,8 +369,7 @@ class HookRelay:
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
|
- def __getattr__(self, name: str) -> HookCaller:
|
|
|
- ...
|
|
|
+ def __getattr__(self, name: str) -> HookCaller: ...
|
|
|
|
|
|
|
|
|
# Historical name (pluggy<=1.2), kept for backward compatibility.
|
|
@@ -690,6 +702,7 @@ class HookSpec:
|
|
|
"kwargnames",
|
|
|
"opts",
|
|
|
"warn_on_impl",
|
|
|
+ "warn_on_impl_args",
|
|
|
)
|
|
|
|
|
|
def __init__(self, namespace: _Namespace, name: str, opts: HookspecOpts) -> None:
|
|
@@ -699,3 +712,4 @@ class HookSpec:
|
|
|
self.argnames, self.kwargnames = varnames(self.function)
|
|
|
self.opts = opts
|
|
|
self.warn_on_impl = opts.get("warn_on_impl")
|
|
|
+ self.warn_on_impl_args = opts.get("warn_on_impl_args")
|