Skip to content

Commit 0beee34

Browse files
committed
mypy passes for private stuff now too, may make it a full-fledged CI step soon
1 parent 40562a0 commit 0beee34

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

src/async_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__author__ = "Michael Hall"
1010
__license__ = "Apache-2.0"
1111
__copyright__ = "Copyright 2020-Present Michael Hall"
12-
__version__ = "2025.03.30b"
12+
__version__ = "2025.04.6b"
1313

1414
import os
1515
import sys

src/async_utils/_paramkey.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ def __eq__(self, other: object) -> bool:
4444
_marker: tuple[object] = (object(),)
4545

4646

47-
def make_key(
47+
def _make_key(
4848
args: tuple[t.Any, ...],
4949
kwds: dict[t.Any, t.Any],
50+
/, *,
5051
_typ: Callable[[object], type] = type,
5152
_fast_types: set[type] = {int, str}, # noqa: B006
5253
) -> Hashable:
@@ -58,3 +59,6 @@ def make_key(
5859
elif len(key) == 1 and _typ(key[0]) in _fast_types:
5960
return key[0]
6061
return _HK(key)
62+
63+
64+
make_key: Callable[[tuple[t.Any, ...], dict[t.Any, t.Any]], Hashable] = _make_key

src/async_utils/corofunc_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def corocache[**P, R](
8282
key_func = make_key
8383
else:
8484

85-
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any]) -> Hashable:
85+
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any], /) -> Hashable:
8686
return make_key(*cache_transform(args, kwds))
8787

8888
def wrapper(coro: CoroLike[P, R]) -> CoroFunc[P, R]:
@@ -161,7 +161,7 @@ def lrucorocache[**P, R](
161161
key_func = make_key
162162
else:
163163

164-
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any]) -> Hashable:
164+
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any], /) -> Hashable:
165165
return make_key(*cache_transform(args, kwds))
166166

167167
def wrapper(coro: CoroLike[P, R]) -> CoroFunc[P, R]:

src/async_utils/task_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def taskcache[**P, R](
142142
key_func = make_key
143143
else:
144144

145-
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any]) -> Hashable:
145+
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any], /) -> Hashable:
146146
return make_key(*cache_transform(args, kwds))
147147

148148
def wrapper(coro: TaskCoroFunc[P, R]) -> TaskFunc[P, R]:
@@ -228,7 +228,7 @@ def lrutaskcache[**P, R](
228228
key_func = make_key
229229
else:
230230

231-
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any]) -> Hashable:
231+
def key_func(args: tuple[t.Any, ...], kwds: dict[t.Any, t.Any], /) -> Hashable:
232232
return make_key(*cache_transform(args, kwds))
233233

234234
def wrapper(coro: TaskCoroFunc[P, R]) -> TaskFunc[P, R]:

src/async_utils/waterfall.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def put(self, item: T) -> None:
115115
raise RuntimeError(msg)
116116
self.queue.put_nowait(item)
117117

118-
def _user_done_callback(self, num: int, future: asyncio.Future[t.Any]):
118+
def _user_done_callback(self, num: int, future: asyncio.Future[t.Any]) -> None:
119119
if future.cancelled():
120120
log.warning("Callback cancelled due to timeout")
121121
elif exc := future.exception():
@@ -151,13 +151,13 @@ async def _dispatch_loop(self) -> None:
151151

152152
# get len before callback may mutate list
153153
num_items = len(queue_items)
154-
t = loop.create_task(self.callback(queue_items))
154+
task = loop.create_task(self.callback(queue_items))
155155
del queue_items
156156

157-
tasks.add(t)
158-
t.add_done_callback(tasks.discard)
157+
tasks.add(task)
158+
task.add_done_callback(tasks.discard)
159159
cb = partial(self._user_done_callback, num_items)
160-
t.add_done_callback(cb)
160+
task.add_done_callback(cb)
161161

162162
finally:
163163
f = loop.create_task(self._finalize())
@@ -181,9 +181,9 @@ async def _dispatch_loop(self) -> None:
181181
except TimeoutError:
182182
# GatheringFuture.cancel doesnt work here
183183
# due to return_exceptions=True
184-
for t in (f, *tasks):
185-
if not t.done():
186-
t.cancel()
184+
for task in (f, *tasks):
185+
if not task.done():
186+
task.cancel()
187187

188188
async def _finalize(self) -> None:
189189
loop = self._event_loop

0 commit comments

Comments
 (0)