11from contextvars import ContextVar
2+ from typing import Callable , Iterator
23
34import anyio
45import pytest
89from starlette .requests import Request
910from starlette .responses import Response
1011from starlette .routing import Route
12+ from starlette .testclient import TestClient
13+
14+ TestClientFactory = Callable [..., TestClient ]
1115
1216
1317@pytest .mark .anyio
14- async def test_run_until_first_complete ():
18+ async def test_run_until_first_complete () -> None :
1519 task1_finished = anyio .Event ()
1620 task2_finished = anyio .Event ()
1721
18- async def task1 ():
22+ async def task1 () -> None :
1923 task1_finished .set ()
2024
21- async def task2 ():
25+ async def task2 () -> None :
2226 await task1_finished .wait ()
2327 await anyio .sleep (0 ) # pragma: nocover
2428 task2_finished .set () # pragma: nocover
@@ -28,7 +32,9 @@ async def task2():
2832 assert not task2_finished .is_set ()
2933
3034
31- def test_accessing_context_from_threaded_sync_endpoint (test_client_factory ) -> None :
35+ def test_accessing_context_from_threaded_sync_endpoint (
36+ test_client_factory : TestClientFactory ,
37+ ) -> None :
3238 ctxvar : ContextVar [bytes ] = ContextVar ("ctxvar" )
3339 ctxvar .set (b"data" )
3440
@@ -45,7 +51,7 @@ def endpoint(request: Request) -> Response:
4551@pytest .mark .anyio
4652async def test_iterate_in_threadpool () -> None :
4753 class CustomIterable :
48- def __iter__ (self ):
54+ def __iter__ (self ) -> Iterator [ int ] :
4955 yield from range (3 )
5056
5157 assert [v async for v in iterate_in_threadpool (CustomIterable ())] == [0 , 1 , 2 ]
0 commit comments