From b85c129ec7547219f19857ec5624e6c77ce75370 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 20 Oct 2026 06:37:35 +0000 Subject: [PATCH 1/2] Document why FixtureRequest.node is not type-annotated Refs #13888. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01FbVKGSuPZFfJpPHTPANBQa --- src/_pytest/fixtures.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 20e43f89132..1a86e55da9b 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -564,6 +564,13 @@ def fixturenames(self) -> list[str]: result.extend(set(self._fixture_defs).difference(result)) return result + # The return type is intentionally left unannotated (implicitly Any). + # The concrete node type depends on the request scope, so the only correct + # annotation would be a broad one (``Item | Collector``). That would force + # users to ``assert isinstance(...)`` or ``cast`` whenever they know the + # actual type (e.g. ``request.node.function`` in a function-scoped + # fixture), so we trade type safety for convenience here. + # See https://github.com/pytest-dev/pytest/issues/13888#issuecomment-3511168937. @property @abc.abstractmethod def node(self): From fec5cb5ec0df3a7bd3a8641a700177c106d9b993 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 05:52:27 +0000 Subject: [PATCH 2/2] Annotate FixtureRequest.node as returning Any Strict pyright reports an unannotated return as Unknown, so spell out the intended Any. Refs #13888. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01FbVKGSuPZFfJpPHTPANBQa --- changelog/13888.improvement.rst | 1 + src/_pytest/fixtures.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelog/13888.improvement.rst diff --git a/changelog/13888.improvement.rst b/changelog/13888.improvement.rst new file mode 100644 index 00000000000..b15231a8b79 --- /dev/null +++ b/changelog/13888.improvement.rst @@ -0,0 +1 @@ +:attr:`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`. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 1a86e55da9b..e3d6300b599 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -564,16 +564,18 @@ def fixturenames(self) -> list[str]: result.extend(set(self._fixture_defs).difference(result)) return result - # The return type is intentionally left unannotated (implicitly Any). + # The return type is intentionally ``Any``. # The concrete node type depends on the request scope, so the only correct # annotation would be a broad one (``Item | Collector``). That would force # users to ``assert isinstance(...)`` or ``cast`` whenever they know the # actual type (e.g. ``request.node.function`` in a function-scoped # fixture), so we trade type safety for convenience here. + # It is spelled out explicitly because pyright in strict mode reports an + # unannotated return as ``Unknown`` rather than ``Any``. # See https://github.com/pytest-dev/pytest/issues/13888#issuecomment-3511168937. @property @abc.abstractmethod - def node(self): + def node(self) -> Any: """Underlying collection node (depends on current request scope).""" raise NotImplementedError()