Skip to content

Commit b42a5d2

Browse files
committed
config: use casts for legacy hook marks instead of type ignores
This is the expected case for casts -- the correct type is ensured dynamically, just too complicated for a type checker to understand.
1 parent b5c0b85 commit b42a5d2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/_pytest/config/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,21 @@ def parse_hookimpl_opts(
472472
if not inspect.isroutine(method):
473473
return None
474474
# Collect unmarked hooks as long as they have the `pytest_' prefix.
475-
return _get_legacy_hook_marks( # type: ignore[return-value]
475+
legacy = _get_legacy_hook_marks(
476476
method, "impl", ("tryfirst", "trylast", "optionalhook", "hookwrapper")
477477
)
478+
return cast(HookimplOpts, legacy)
478479

479480
def parse_hookspec_opts(self, module_or_class, name: str) -> HookspecOpts | None:
480481
""":meta private:"""
481482
opts = super().parse_hookspec_opts(module_or_class, name)
482483
if opts is None:
483484
method = getattr(module_or_class, name)
484485
if name.startswith("pytest_"):
485-
opts = _get_legacy_hook_marks( # type: ignore[assignment]
486-
method,
487-
"spec",
488-
("firstresult", "historic"),
486+
legacy = _get_legacy_hook_marks(
487+
method, "spec", ("firstresult", "historic")
489488
)
489+
opts = cast(HookspecOpts, legacy)
490490
return opts
491491

492492
def register(self, plugin: _PluggyPlugin, name: str | None = None) -> str | None:

0 commit comments

Comments
 (0)