Skip to content

Commit ae37a01

Browse files
Merge pull request #15227 from pytest-dev/claude/project-thread-4etye4
Annotate FixtureRequest.node as Any and document why
2 parents 7d646b5 + 3fd4ebd commit ae37a01

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎changelog/13888.misc.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:attr:`FixtureRequest.node <pytest.FixtureRequest.node>` is now explicitly annotated as returning ``Any``, so strict pyright no longer reports it as ``Unknown``. The return type stays deliberately broad, see :issue:`13888`.

‎src/_pytest/fixtures.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,18 @@ def fixturenames(self) -> list[str]:
564564
result.extend(set(self._fixture_defs).difference(result))
565565
return result
566566

567+
# The return type is intentionally ``Any``.
568+
# The concrete node type depends on the request scope, so the only correct
569+
# annotation would be a broad one (``Item | Collector``). That would force
570+
# users to ``assert isinstance(...)`` or ``cast`` whenever they know the
571+
# actual type (e.g. ``request.node.function`` in a function-scoped
572+
# fixture), so we trade type safety for convenience here.
573+
# It is spelled out explicitly because pyright in strict mode reports an
574+
# unannotated return as ``Unknown`` rather than ``Any``.
575+
# See https://github.com/pytest-dev/pytest/issues/13888#issuecomment-3511168937.
567576
@property
568577
@abc.abstractmethod
569-
def node(self):
578+
def node(self) -> Any:
570579
"""Underlying collection node (depends on current request scope)."""
571580
raise NotImplementedError()
572581

0 commit comments

Comments
 (0)