Skip to content

Improve type annotation for twisted.internet.defer.Deferred.fromFuture #11753

@babolivier

Description

@babolivier

Is your feature request related to a problem? Please describe.

Deferred.fromFuture is annotated as returning Deferred[Any]. While this is technically correct (since Any means "any type"), it can easily be improved. Moreover, it causes projects using strict mypy checks to necessitate additional annotations.

Describe the solution you'd like

One could improve the type annotation of this method in this way:

_T = TypeVar("T")

...

    @classmethod
    def fromFuture(cls, future: Future[_T]) -> "Deferred[_T]":

Describe alternatives you've considered

An alternative would be leaving things as is, but as I've mentioned that requires the project that calls fromFuture to add type annotations that could be inferred from fromFuture's.

Additional context

Here is an example of code that requires such superfluous annotation: to make mypy happy, d needs to be annotated as a Deferred[MediaDescription], even though that can be inferred from the fact that the values in self._current_scans are already annotated as Future[MediaDescription].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions