simplify typing for legacy hook mark support
This commit is contained in:
parent
b1fb9a9c8d
commit
e3294398d6
|
@ -344,10 +344,13 @@ def _get_directory(path: Path) -> Path:
|
||||||
|
|
||||||
|
|
||||||
def _get_legacy_hook_marks(
|
def _get_legacy_hook_marks(
|
||||||
method: object, # using object to avoid function type excess
|
method: Any,
|
||||||
hook_type: str,
|
hook_type: str,
|
||||||
opt_names: Tuple[str, ...],
|
opt_names: Tuple[str, ...],
|
||||||
) -> Dict[str, bool]:
|
) -> 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", [])}
|
known_marks: set[str] = {m.name for m in getattr(method, "pytestmark", [])}
|
||||||
must_warn: list[str] = []
|
must_warn: list[str] = []
|
||||||
opts: dict[str, bool] = {}
|
opts: dict[str, bool] = {}
|
||||||
|
@ -365,7 +368,7 @@ def _get_legacy_hook_marks(
|
||||||
hook_opts = ", ".join(must_warn)
|
hook_opts = ", ".join(must_warn)
|
||||||
message = _pytest.deprecated.HOOK_LEGACY_MARKING.format(
|
message = _pytest.deprecated.HOOK_LEGACY_MARKING.format(
|
||||||
type=hook_type,
|
type=hook_type,
|
||||||
fullname=method.__qualname__, # type: ignore
|
fullname=method.__qualname__,
|
||||||
hook_opts=hook_opts,
|
hook_opts=hook_opts,
|
||||||
)
|
)
|
||||||
warn_explicit_for(cast(FunctionType, method), message)
|
warn_explicit_for(cast(FunctionType, method), message)
|
||||||
|
|
Loading…
Reference in New Issue