Skip to content

Commit 3a78b12

Browse files
authored
Merge pull request #228 from aiokitchen/threaded-typing
Threaded typing
2 parents 8e85546 + 78be209 commit 3a78b12

25 files changed

+1713
-1264
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313

1414
- uses: actions/checkout@v2
1515

16-
- name: Setup python3.9
16+
- name: Setup python3.10
1717
uses: actions/setup-python@v2
1818
with:
19-
python-version: "3.9"
19+
python-version: "3.10"
2020

2121
- name: Resetting git to master
2222
run: git reset --hard master

.github/workflows/tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ jobs:
5555

5656
matrix:
5757
python:
58-
- '3.9'
5958
- '3.10'
6059
- '3.11'
6160
- '3.12'
@@ -117,7 +116,6 @@ jobs:
117116

118117
matrix:
119118
python:
120-
- '3.9'
121119
- '3.10'
122120
- '3.11'
123121
steps:

aiomisc/entrypoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def _on_interrupt(self, loop: asyncio.AbstractEventLoop) -> None:
419419
handle = loop.call_later(self.shutdown_timeout, task.cancel)
420420

421421
def on_shutdown_finish(task: asyncio.Future) -> None:
422-
nonlocal handle, loop
422+
nonlocal handle, loop # noqa
423423

424424
if task.cancelled():
425425
log.warning(

aiomisc/iterator_wrapper.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from types import TracebackType
1010
from typing import (
1111
Any, AsyncIterator, Awaitable, Callable, Deque, Generator, NoReturn,
12-
Optional, Type, TypeVar, Union,
12+
Optional, Type, TypeVar, Union, Generic, ParamSpec,
1313
)
1414
from weakref import finalize
1515

@@ -19,8 +19,9 @@
1919

2020
T = TypeVar("T")
2121
R = TypeVar("R")
22+
P = ParamSpec("P")
2223

23-
GenType = Generator[T, R, None]
24+
GenType = Generator[T, None, None]
2425
FuncType = Callable[[], GenType]
2526

2627

@@ -144,7 +145,7 @@ class IteratorWrapperStatistic(Statistic):
144145
enqueued: int
145146

146147

147-
class IteratorWrapper(AsyncIterator, EventLoopMixin):
148+
class IteratorWrapper(Generic[P, T], AsyncIterator, EventLoopMixin):
148149
__slots__ = (
149150
"__channel",
150151
"__close_event",
@@ -155,9 +156,11 @@ class IteratorWrapper(AsyncIterator, EventLoopMixin):
155156
) + EventLoopMixin.__slots__
156157

157158
def __init__(
158-
self, gen_func: FuncType,
159+
self,
160+
gen_func: Callable[P, Generator[T, None, None]],
159161
loop: Optional[asyncio.AbstractEventLoop] = None,
160-
max_size: int = 0, executor: Optional[Executor] = None,
162+
max_size: int = 0,
163+
executor: Optional[Executor] = None,
161164
statistic_name: Optional[str] = None,
162165
):
163166

@@ -227,11 +230,9 @@ async def wait_closed(self) -> None:
227230
await asyncio.gather(self.__gen_task, return_exceptions=True)
228231

229232
def _run(self) -> Any:
230-
return self.loop.run_in_executor(
231-
self.executor, self._in_thread,
232-
)
233+
return self.loop.run_in_executor(self.executor, self._in_thread)
233234

234-
def __aiter__(self) -> AsyncIterator[Any]:
235+
def __aiter__(self) -> AsyncIterator[T]:
235236
if not self.loop.is_running():
236237
raise RuntimeError("Event loop is not running")
237238

@@ -242,7 +243,7 @@ def __aiter__(self) -> AsyncIterator[Any]:
242243
self.__gen_task = gen_task
243244
return IteratorProxy(self, self.close)
244245

245-
async def __anext__(self) -> Awaitable[T]:
246+
async def __anext__(self) -> T:
246247
try:
247248
item, is_exc = await self.__channel.get()
248249
except ChannelClosed:
@@ -269,13 +270,13 @@ async def __aexit__(
269270
await self.close()
270271

271272

272-
class IteratorProxy(AsyncIterator):
273+
class IteratorProxy(Generic[T], AsyncIterator):
273274
def __init__(
274-
self, iterator: AsyncIterator,
275+
self, iterator: AsyncIterator[T],
275276
finalizer: Callable[[], Any],
276277
):
277278
self.__iterator = iterator
278279
finalize(self, finalizer)
279280

280-
def __anext__(self) -> Awaitable[Any]:
281+
def __anext__(self) -> Awaitable[T]:
281282
return self.__iterator.__anext__()

aiomisc/service/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import asyncio
22
from abc import ABC, ABCMeta, abstractmethod
3-
from typing import (
4-
Any, Coroutine, Dict, Generator, Optional, Set, Tuple, TypeVar, Union,
5-
)
3+
from typing import Any, Coroutine, Dict, Optional, Set, Tuple, TypeVar, Union
64

75
from ..context import Context, get_context
86
from ..utils import cancel_tasks
97

108

119
T = TypeVar("T")
12-
CoroutineType = Union[Coroutine[Any, Any, T], Generator[Any, None, T]]
10+
CoroutineType = Union[Coroutine[Any, Any, T]]
1311

1412

1513
class ServiceMeta(ABCMeta):

0 commit comments

Comments
 (0)