celery-types icon indicating copy to clipboard operation
celery-types copied to clipboard

Wrong type stubs for EagerResult

Open oliverhaas opened this issue 2 months ago • 0 comments

The type stub for EagerResult doesn't have its own __init__ defined, so type checkers think it just inherits from AsyncResult and then complain when you use it correctly.

Here's what the actual Celery code looks like:

class EagerResult(AsyncResult):
    def __init__(self, id, ret_value, state, traceback=None, name=None):
        ...

But the stub in celery-stubs/result.pyi is just:

class EagerResult(AsyncResult[_R]): ...

So mypy/pyright think you're supposed to call it like AsyncResult.__init__:

def __init__(
    self,
    id: str,
    backend: Backend | None = ...,
    task_name: str | None = ...,
    app: Celery | None = ...,
    parent: ResultBase | None = ...,
) -> None: ...

Which means this perfectly valid code:

result = EagerResult("task-123", {"status": "done"}, "SUCCESS")

Gets type errors about wrong number of arguments, wrong types, etc.

Quick fix would be to add the actual signature to the stub, I think. I will make a PR with this in a minute.

class EagerResult(AsyncResult[_R]):
    def __init__(
        self,
        id: str,
        ret_value: _R,
        state: str,
        traceback: str | None = ...,
        name: str | None = ...,
    ) -> None: ...

oliverhaas avatar Nov 02 '25 13:11 oliverhaas