From e3294398d6912a4c3d28dadb6087c3ab8974582a Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 20 Sep 2022 15:53:53 +0200 Subject: [PATCH] simplify typing for legacy hook mark support --- src/_pytest/config/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 2d6693808..51d79deba 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -344,10 +344,13 @@ def _get_directory(path: Path) -> Path: def _get_legacy_hook_marks( - method: object, # using object to avoid function type excess + method: Any, hook_type: str, opt_names: Tuple[str, ...], ) -> Dict[str, bool]: + if TYPE_CHECKING: + # abuse typeguard from importlib to avoid massive method type union thats lacking a alias + assert inspect.isroutine(method) known_marks: set[str] = {m.name for m in getattr(method, "pytestmark", [])} must_warn: list[str] = [] opts: dict[str, bool] = {} @@ -365,7 +368,7 @@ def _get_legacy_hook_marks( hook_opts = ", ".join(must_warn) message = _pytest.deprecated.HOOK_LEGACY_MARKING.format( type=hook_type, - fullname=method.__qualname__, # type: ignore + fullname=method.__qualname__, hook_opts=hook_opts, ) warn_explicit_for(cast(FunctionType, method), message)