The types of Celery.task loose type information because they return a _T_Global in some cases. This is different to how shared_task is typed.
The code below shows how the type information is lost:
from typing import reveal_type
import celery
celery_app = celery.Celery()
@celery_app.task()
def task1(a: int) -> int:
return a
@celery.shared_task()
def task2(a: int) -> int:
return a
reveal_type(task1)
reveal_type(task2)
Mypy, pyright show these types:
tasks2.py:15: note: Revealed type is "celery.app.task.Task[Any, Any]"
tasks2.py:16: note: Revealed type is "celery.app.task.Task[[a: int], int]"
The types of Celery.task loose type information because they return a _T_Global in some cases. This is different to how shared_task is typed.
The code below shows how the type information is lost:
Mypy, pyright show these types: