Skip to content

Adds type annotations to FixtureRequest.node - #15103

Open
Contrabang wants to merge 5 commits into
pytest-dev:mainfrom
Contrabang:node-type-annotations
Open

Contrabang wants to merge 5 commits into
pytest-dev:mainfrom
Contrabang:node-type-annotations

Conversation

@Contrabang

@Contrabang Contrabang commented Sep 25, 2026 •

Copy link
Copy Markdown

Recommended reading: #7469 (comment)

Adds type annotations to FixtureRequest's node property. This type annotation is further narrowed down for the _pytest subclasses. This allows typecheckers like pyright to correctly determine node's type, where it would previously return "Unknown"

This alters the record_property for junitxml.py slightly, adding a cast of request.node to Item where the user_properties variable is defined. I couldn't find a way to restrict the types for the node property in a way to allow this without a cast.

cast() has no performance impact, nor any assertions that stop the code from continuing. It simply tells the type checker what to expect. This will have functionally no impact on that function in production, as it would have errored when trying to access Unknown.user_properties in cases where node is not nodes.Item

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 25, 2026
@Contrabang
Contrabang marked this pull request as draft September 25, 2026 22:22
@Contrabang
Contrabang marked this pull request as ready for review September 25, 2026 23:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant