22import contextlib
33import functools
44import 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
88import 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 )
0 commit comments