Skip to content

Commit

Permalink
Merge pull request #44 from Doist/proxi/add-types-3
Browse files Browse the repository at this point in the history
chore: Partial typing.
  • Loading branch information
proxi committed Oct 24, 2023
2 parents 5e661ae + dfc068e commit acfaa94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions sqs_workers/async_task.py
Expand Up @@ -3,6 +3,7 @@
from contextlib import contextmanager
from typing import (
TYPE_CHECKING,
Any,
Callable,
Generator,
Generic,
Expand All @@ -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
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sqs_workers/queue.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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
"""
Expand Down

0 comments on commit acfaa94

Please sign in to comment.