Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
babolivier opened this issue Nov 8, 2022 · 0 comments · Fixed by #11770
Closed

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

babolivier opened this issue Nov 8, 2022 · 0 comments · Fixed by #11770

Comments

@babolivier
Copy link
Contributor

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].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant