5656_ScopeName = Literal ["session" , "package" , "module" , "class" , "function" ]
5757_T = TypeVar ("_T" )
5858
59- SimpleFixtureFunction = TypeVar (
60- "SimpleFixtureFunction" , bound = Callable [..., Awaitable [object ]]
59+ FixtureFunctionT = TypeVar (
60+ "FixtureFunctionT" ,
61+ bound = Union [Callable [..., Awaitable [Any ]], Callable [..., AsyncIterator [Any ]]],
6162)
62- FactoryFixtureFunction = TypeVar (
63- "FactoryFixtureFunction" , bound = Callable [..., AsyncIterator [object ]]
63+ FixtureFunctionU = TypeVar (
64+ "FixtureFunctionU" ,
65+ bound = Union [Callable [..., Awaitable [Any ]], Callable [..., AsyncIterator [Any ]]],
6466)
65- FixtureFunction = Union [SimpleFixtureFunction , FactoryFixtureFunction ]
66- FixtureFunctionMarker = Callable [[FixtureFunction ], FixtureFunction ]
67+ FixtureFunctionType = Union [
68+ Callable [..., Awaitable [Any ]], Callable [..., AsyncIterator [Any ]]
69+ ]
70+ FixtureFunctionMarker = Callable [[FixtureFunctionT ], FixtureFunctionT ]
6771
6872
6973class PytestAsyncioError (Exception ):
@@ -117,7 +121,7 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None
117121
118122@overload
119123def fixture (
120- fixture_function : FixtureFunction ,
124+ fixture_function : FixtureFunctionT ,
121125 * ,
122126 scope : _ScopeName | Callable [[str , Config ], _ScopeName ] = ...,
123127 loop_scope : _ScopeName | None = ...,
@@ -129,7 +133,7 @@ def fixture(
129133 | None
130134 ) = ...,
131135 name : str | None = ...,
132- ) -> FixtureFunction : ...
136+ ) -> FixtureFunctionT : ...
133137
134138
135139@overload
@@ -146,22 +150,22 @@ def fixture(
146150 | None
147151 ) = ...,
148152 name : str | None = None ,
149- ) -> FixtureFunctionMarker : ...
153+ ) -> FixtureFunctionMarker [ FixtureFunctionU ] : ...
150154
151155
152156def fixture (
153- fixture_function : FixtureFunction | None = None ,
157+ fixture_function : FixtureFunctionT | None = None ,
154158 loop_scope : _ScopeName | None = None ,
155159 ** kwargs : Any ,
156- ) -> FixtureFunction | FixtureFunctionMarker :
160+ ) -> FixtureFunctionT | FixtureFunctionMarker [ FixtureFunctionU ] :
157161 if fixture_function is not None :
158162 _make_asyncio_fixture_function (fixture_function , loop_scope )
159163 return pytest .fixture (fixture_function , ** kwargs )
160164
161165 else :
162166
163167 @functools .wraps (fixture )
164- def inner (fixture_function : FixtureFunction ) -> FixtureFunction :
168+ def inner (fixture_function : FixtureFunctionU ) -> FixtureFunctionU :
165169 return fixture (fixture_function , loop_scope = loop_scope , ** kwargs )
166170
167171 return inner
@@ -679,7 +683,9 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
679683
680684# A stack used to push package-scoped loops during collection of a package
681685# and pop those loops during collection of a Module
682- __package_loop_stack : list [FixtureFunctionMarker | FixtureFunction ] = []
686+ __package_loop_stack : list [
687+ FixtureFunctionMarker [FixtureFunctionType ] | FixtureFunctionType
688+ ] = []
683689
684690
685691@pytest .hookimpl
0 commit comments