Skip to content

Use typing annotations in Celery (PEP 484)? #7258

@atombrella

Description

@atombrella

Mainly intended as a question. There are a lot of type annotations as comment (compatible with Python 2). Some of them are outdated, as new arguments have since then been added to the functions. Are there plans to add type annotations to Celery, and enforce them as well? It's my experience that it increases readability of the code (and also IDE support), and may also find some bugs. I do know that not everyone is a big fan of this new addition in Python.

I couldn't find any issue relating this; searching for typing and mypy didn't yield results (only lists with packages from pip freeze).

https://github.com/ilevkivskyi/com2ann is a neat tool for doing the hard work.
https://www.python.org/dev/peps/pep-0484/

This is one example of a class with both type comments. The type for _evict does not reflect the current arguments.

class Evictable:
    """Mixin for classes supporting the ``evict`` method."""

    Empty = Empty

    def evict(self):
        # type: () -> None
        """Force evict until maxsize is enforced."""
        self._evict(range=count)

    def _evict(self, limit=100, range=range):
        # type: (int) -> None
        try:
            [self._evict1() for _ in range(limit)]
        except IndexError:
            pass

    def _evict1(self):
        # type: () -> None
        if self._evictcount <= self.maxsize:
            raise IndexError()
        try:
            self._pop_to_evict()
        except self.Empty:
            raise IndexError()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions