You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There have been times I really wanted to override the types that PyCharm has guessed for a lambda fixture's expression. It would be nice if I could explicitly type the lambda fixture lhs, so I wouldn't have to curry this typing info to every test I use the fixture in (and which would be impossible to do inside other lambda params). Something like:
It would be real nice if pytest itself exposed its types publicly, as it has what we need:
# The value of the fixture -- return/yield of the fixture function (type variable)._FixtureValue=TypeVar("_FixtureValue")
# The type of a fixture function (type alias generic in fixture value)._FixtureFunc=Union[
Callable[..., _FixtureValue], Callable[..., Generator[_FixtureValue, None, None]]
]
Though, those types kinda fall down when async is involved — the actual value of the fixture is not what the fixture callable returns; in those cases, the callable would return a Coroutine, but that's not what test methods/fixtures would see when requesting the fixture.
Setting the type of the declaration directly to the fixture value type doesn't quite cut it, because the actual object returned by lambda_fixture() is a callable, just like any other pytest fixture function. It would be incorrect to lose this information. Perhaps the best approach might be to make LambdaFixture generic, ignore async deets, and call it a day.
The text was updated successfully, but these errors were encountered:
In version 2.2.0, I made LambdaFixture generic. This should at least open the door to explicitly declaring the fixture value type. However, handling destructured lambda fixtures hasn't really been fleshed out.
There have been times I really wanted to override the types that PyCharm has guessed for a lambda fixture's expression. It would be nice if I could explicitly type the lambda fixture lhs, so I wouldn't have to curry this typing info to every test I use the fixture in (and which would be impossible to do inside other lambda params). Something like:
It would be real nice if pytest itself exposed its types publicly, as it has what we need:
Though, those types kinda fall down when async is involved — the actual value of the fixture is not what the fixture callable returns; in those cases, the callable would return a
Coroutine
, but that's not what test methods/fixtures would see when requesting the fixture.Setting the type of the declaration directly to the fixture value type doesn't quite cut it, because the actual object returned by
lambda_fixture()
is a callable, just like any other pytest fixture function. It would be incorrect to lose this information. Perhaps the best approach might be to makeLambdaFixture
generic, ignore async deets, and call it a day.The text was updated successfully, but these errors were encountered: