Skip to content

type hinting for request.param (such as SubRequest[MyType])Β #8763

Open
@altendky

Description

@altendky

I could presumably submit a PR for this if it making SubRequest a Generic is deemed a good approach.

What's the problem this feature will solve?

When type hinting a parameter for a request fixture the request.param attribute is typed as Any and I have to # type: ignore[no-any-return].

Describe the solution you'd like

Long term, a plugin would be nice to automatically relate the .param to it's source in the @pytest.fixture() decoration. Short term, Request could just be a Generic.

This would allow me to use request: _pytest.fixtures.SubRequest[MyType] instead of the type ignore and get any useful hints on the .param attribute inside the fixture as well as return type verification.

Alternative Solutions

I have not tried anything beyond the type ignore.

Additional context

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytopic: typingtype-annotation issuetype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions