Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

celery: More precise typing for Celery.register_task(...) #168

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions celery-stubs/app/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,7 @@ class Celery:
) -> Callable[
[Callable[Concatenate[CeleryTask[_P, _R], _P], _R]], CeleryTask[_P, _R]
]: ...
def register_task(
self,
task: CeleryTask[Any, Any] | type[CeleryTask[Any, Any]],
**options: Any,
) -> CeleryTask[Any, Any]: ...
def register_task(self, task: _T | type[_T], **options: Any) -> _T: ...
def gen_task_name(self, name: str, module: str) -> str: ...
def finalize(self, auto: bool = ...) -> None: ...
def add_defaults(self, fun: Callable[[], dict[str, Any]]) -> None: ...
Expand Down
8 changes: 8 additions & 0 deletions tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def add_3(x: int, y: int) -> None:
add_3.foo()


def test_celery_register_task() -> None:
bar = app_2.register_task(MyTask())
bar.foo()

baz = app_2.register_task(MyTask)
baz.foo()


def test_celery_calling_task() -> None:
signature("tasks.add", args=(2, 2), countdown=10)

Expand Down
Loading