-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add typing information for parameterized fixtures #8073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@bluetech would it be sensible to introduce a generic protocol here ? |
Thanks for bringing this up @tobiasdiez. This seems doable but would require some work: The For unparametrized fixtures, pytest currently leaves Python/mypy currently does not support giving defaults to type parameters, so this will be a bit of an ergonomic hit for annotating with |
im happy to have 2 types for that, the fixture decorator could even apply it based on params and/or a flag for the param type required then mypy would fail with missing attribute for non-parameterized fixtures while giving off the exxact type in the other case |
On a related note: I'm happy to just add a We did something similar with |
Parameter values may be none, we either have to have a extra flag for indication, or a singleton type |
Any plans to implement this feature anytime soon? |
For now, mark it as Any until pytest-dev#8073 is solved Fixes pytest-dev#9514
For now, mark it as Any until pytest-dev#8073 is solved Fixes pytest-dev#9514
For now, mark it as Any until pytest-dev#8073 is solved Fixes pytest-dev#9514
What's the problem this feature will solve?
Add typing information for parameterized fixtures to have better support for type checkers.
Describe the solution you'd like
Given a fixture like
what is the type of
request
? I thought it would beFixtureRequest
but this class doesn't have aparam
object. Thus I suggest to add a generic classParametrizedFixtureRequest[T]
whereT
is the type of the parameter. Thus in the above example one could annotaterequest: ParametrizedFixtureRequest[str]
and then the type checker would know thatrequest.param
is a string.Alternative Solutions
Additional context
The text was updated successfully, but these errors were encountered: