Skip to content

Commit 801e73e

Browse files
TechNiickScirlat Danut
andauthored
Add type hints to test_concurency.py (#2474)
Co-authored-by: Scirlat Danut <[email protected]>
1 parent 88331bd commit 801e73e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/test_concurrency.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from contextvars import ContextVar
2+
from typing import Callable, Iterator
23

34
import anyio
45
import pytest
@@ -8,17 +9,20 @@
89
from starlette.requests import Request
910
from starlette.responses import Response
1011
from 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
4652
async 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

Comments
 (0)