sbdchd / celery-types

:seedling: Type stubs for Celery and its related packages
Apache License 2.0
87 stars 41 forks source link

celery: More precise typing for Task.replace(...) #165

Closed alecbarber closed 3 days ago

alecbarber commented 3 days ago

Resolves #166

Task.replace() either applys the provided signature eagerly, or raises Ignore [1]. Here's a silly example which this PR fixes:

from celery import Celery, Task

app = Celery()

@app.task(bind=True)
def maybe_replace(task: Task, replace: bool) -> int:
    if replace:
        return task.replace(maybe_replace.s(replace=False))   # type: ignore[func-returns-value]
    else:
        return 10

[1] https://github.com/celery/celery/blob/1b35d1d5966614ce36af75808ee21b0d2db6745d/celery/app/task.py#L1105-L1109

sbdchd commented 3 days ago

Thank you!