Skip to content

Commit 9970d72

Browse files
committed
fixes mypy with futures
1 parent 95f2213 commit 9970d72

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/service-library/src/servicelib/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async def limited_as_completed(
197197
*,
198198
limit: int = _DEFAULT_LIMITED_CONCURRENCY,
199199
tasks_group_prefix: str | None = None,
200-
) -> AsyncGenerator[asyncio.Future[T], None]:
200+
) -> AsyncGenerator[asyncio.Task[T], None]:
201201
"""Runs awaitables using limited concurrent tasks and returns
202202
result futures unordered.
203203
@@ -214,7 +214,7 @@ async def limited_as_completed(
214214
nothing
215215
216216
Yields:
217-
Future[T]: the future of the awaitables as they appear.
217+
task[T]: the future of the awaitables as they appear.
218218
219219
220220
"""
@@ -227,7 +227,7 @@ async def limited_as_completed(
227227
is_async = False
228228

229229
completed_all_awaitables = False
230-
pending_futures: set[asyncio.Future] = set()
230+
pending_futures: set[asyncio.Task] = set()
231231

232232
try:
233233
while pending_futures or not completed_all_awaitables:
@@ -240,10 +240,11 @@ async def limited_as_completed(
240240
if is_async
241241
else next(awaitable_iterator) # type: ignore[call-overload]
242242
)
243-
future = asyncio.ensure_future(aw)
243+
future: asyncio.Task = asyncio.ensure_future(aw)
244244
if tasks_group_prefix:
245245
future.set_name(f"{tasks_group_prefix}-{future.get_name()}")
246246
pending_futures.add(future)
247+
247248
except (StopIteration, StopAsyncIteration): # noqa: PERF203
248249
completed_all_awaitables = True
249250
if not pending_futures:
@@ -254,6 +255,7 @@ async def limited_as_completed(
254255

255256
for future in done:
256257
yield future
258+
257259
except asyncio.CancelledError:
258260
for future in pending_futures:
259261
future.cancel()

packages/service-library/src/servicelib/utils_secrets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import secrets
22
import string
3-
from typing import Final
3+
from typing import Any, Final
44

55
from pydantic import StrictInt, validate_arguments
66

@@ -68,7 +68,7 @@ def _is_possibly_sensitive(name: str, sensitive_keywords: set[str]) -> bool:
6868

6969

7070
def mask_sensitive_data(
71-
data: dict, *, extra_sensitive_keywords: set[str] | None = None
71+
data: dict[str, Any], *, extra_sensitive_keywords: set[str] | None = None
7272
) -> dict:
7373
"""Replaces the sensitive values in the dict with a placeholder before logging
7474
@@ -79,7 +79,7 @@ def mask_sensitive_data(
7979
sensitive_keywords = _DEFAULT_SENSITIVE_KEYWORDS | (
8080
extra_sensitive_keywords or set()
8181
)
82-
masked_data = {}
82+
masked_data: dict[str, Any] = {}
8383
for key, value in data.items():
8484
if isinstance(value, dict):
8585
masked_data[key] = mask_sensitive_data(

0 commit comments

Comments
 (0)