Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/13888.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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`.
11 changes: 10 additions & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,18 @@ def fixturenames(self) -> list[str]:
result.extend(set(self._fixture_defs).difference(result))
return result

# 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()

Expand Down
Loading