Skip to content

Commit e329439

Browse files
simplify typing for legacy hook mark support
1 parent b1fb9a9 commit e329439

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/_pytest/config/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,13 @@ def _get_directory(path: Path) -> Path:
344344

345345

346346
def _get_legacy_hook_marks(
347-
method: object, # using object to avoid function type excess
347+
method: Any,
348348
hook_type: str,
349349
opt_names: Tuple[str, ...],
350350
) -> Dict[str, bool]:
351+
if TYPE_CHECKING:
352+
# abuse typeguard from importlib to avoid massive method type union thats lacking a alias
353+
assert inspect.isroutine(method)
351354
known_marks: set[str] = {m.name for m in getattr(method, "pytestmark", [])}
352355
must_warn: list[str] = []
353356
opts: dict[str, bool] = {}
@@ -365,7 +368,7 @@ def _get_legacy_hook_marks(
365368
hook_opts = ", ".join(must_warn)
366369
message = _pytest.deprecated.HOOK_LEGACY_MARKING.format(
367370
type=hook_type,
368-
fullname=method.__qualname__, # type: ignore
371+
fullname=method.__qualname__,
369372
hook_opts=hook_opts,
370373
)
371374
warn_explicit_for(cast(FunctionType, method), message)

0 commit comments

Comments
 (0)