diff --git a/sqs_workers/async_task.py b/sqs_workers/async_task.py index d6e1652..43e6596 100644 --- a/sqs_workers/async_task.py +++ b/sqs_workers/async_task.py @@ -3,6 +3,7 @@ from contextlib import contextmanager from typing import ( TYPE_CHECKING, + Any, Callable, Generator, Generic, @@ -18,12 +19,11 @@ P = ParamSpec("P") -R = TypeVar("R") -class AsyncTask(Generic[P, R]): +class AsyncTask(Generic[P]): def __init__( - self, queue: JobQueue, job_name: str, processor: Callable[P, R] + self, queue: JobQueue, job_name: str, processor: Callable[P, Any] ) -> None: self.queue = queue self.job_name = job_name @@ -40,7 +40,7 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> NoReturn: def __repr__(self) -> str: return "<%s %s.%s>" % (self.__class__.__name__, self.queue.name, self.job_name) - def run(self, *args: P.args, **kwargs: P.kwargs) -> R: + def run(self, *args: P.args, **kwargs: P.kwargs) -> NoReturn: """ Run the task synchronously. """ @@ -61,7 +61,7 @@ def batch(self) -> Generator[None, None, None]: with self.queue.add_batch(): yield - def delay(self, *args: P.args, **kwargs: P.kwargs) -> R: + def delay(self, *args: P.args, **kwargs: P.kwargs) -> str | None: """ Run the task asynchronously. """ @@ -85,7 +85,7 @@ def delay(self, *args: P.args, **kwargs: P.kwargs) -> R: **kwargs, ) - def bake(self, *args: P.args, **kwargs: P.kwargs): + def bake(self, *args: P.args, **kwargs: P.kwargs) -> BakedAsyncTask: """ Create a baked version of the async task, which contains the reference to a queue and task, as well as all arguments which needs to be passed diff --git a/sqs_workers/queue.py b/sqs_workers/queue.py index f4c6c87..a4af804 100644 --- a/sqs_workers/queue.py +++ b/sqs_workers/queue.py @@ -504,7 +504,7 @@ def add_job( _deduplication_id=None, _group_id: Optional[str] = None, **job_kwargs - ): + ) -> str | None: """ Add job to the queue. The body of the job will be converted to the text with one of the codecs (by default it's "pickle_compat") @@ -533,7 +533,7 @@ def add_raw_job( delay_seconds, deduplication_id, group_id: Optional[str], - ): + ) -> str | None: """ Low-level function to put message to the queue """