Skip to content

@app.task should copy __annotations__ from the task function like @functools.wraps #6186

@davidparsson

Description

@davidparsson

Checklist

  • I have checked the issues list
    for similar or identical feature requests.
  • I have checked the pull requests list
    for existing proposed implementations of this feature.
  • I have checked the commit log
    to find out if the if the same feature was already implemented in the
    master branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).

Related Issues and Possible Duplicates

Related Issues

  • None

Possible Duplicates

  • None

Brief Summary

Design

Architectural Considerations

None

Proposed Behavior

Celery tasks created with @app.task should support typing.get_type_hints(my_celery_task).

It can be solved by copying the __annotations__ from the decorated function when available. This is done by functools.wraps() in Python 3.0+, if I understand PEP 3107 correctly. Without this typing.get_type_hints(my_celery_task) raises an exception.

It is my understanding that some other similar properties that functools.wraps handles are already copied:

celery/celery/app/base.py

Lines 453 to 454 in d3863d9

'__doc__': fun.__doc__,
'__module__': fun.__module__,

Proposed UI/UX

Diagrams

N/A

Alternatives

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions