Skip to content

Commit 084785a

Browse files
committed
typing
1 parent dfc782d commit 084785a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/service-library/src/servicelib/redis/_decorators.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import contextlib
33
import functools
44
import logging
5-
from collections.abc import Callable, Coroutine
6-
from typing import Any, ParamSpec, TypeVar
5+
from collections.abc import Callable
6+
from typing import Awaitable, ParamSpec, TypeVar
77

88
import redis.exceptions
99

@@ -25,9 +25,7 @@ def exclusive(
2525
*,
2626
lock_key: str | Callable[..., str],
2727
lock_value: bytes | str | None = None,
28-
) -> Callable[
29-
[Callable[P, Coroutine[Any, Any, R]]], Callable[P, Coroutine[Any, Any, R]]
30-
]:
28+
) -> Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[R]]]:
3129
"""
3230
Define a method to run exclusively across
3331
processes by leveraging a Redis Lock.
@@ -47,8 +45,8 @@ def exclusive(
4745
raise ValueError(msg)
4846

4947
def decorator(
50-
func: Callable[P, Coroutine[Any, Any, R]],
51-
) -> Callable[P, Coroutine[Any, Any, R]]:
48+
func: Callable[P, Awaitable[R]],
49+
) -> Callable[P, Awaitable[R]]:
5250
@functools.wraps(func)
5351
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
5452
redis_lock_key = (
@@ -75,6 +73,7 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
7573
raise_on_error=True,
7674
lock=lock,
7775
) as auto_extend_task:
76+
assert asyncio.iscoroutinefunction(func) # nosec
7877
work_task = asyncio.create_task(
7978
func(*args, **kwargs), name=f"exclusive_{func.__name__}"
8079
)

packages/service-library/src/servicelib/redis/_distributed_locks_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from collections.abc import Awaitable, Callable
55

66
import arrow
7-
from servicelib.background_task import start_periodic_task
87

8+
from ..background_task import start_periodic_task
99
from ._client import RedisClientSDK
1010
from ._decorators import exclusive
1111
from ._errors import CouldNotAcquireLockError

0 commit comments

Comments
 (0)