Skip to content

Deferred's type annotations are generally wrong #11772

Closed
@glyph

Description

@glyph

The current type annotations have a number of issues:

  • _DeferredResultT is contravariant, which is confusing and inaccurate; it should be invariant
  • addCallback, addErrback, and addBoth don't check their callbacks' signatures at all; you don't have to accept a Failure for the latter two, to say nothing of the rest of the signature.
  • Deferred.fromFuture uses an unspecialized generic (see Improve type annotation for twisted.internet.defer.Deferred.fromFuture #11753)
  • maybeDeferred incorrectly returns a Deferred[Deferred[X]] if its function returns a deferred

Some of these are due to new features in Mypy that have come out since the type hints were added, some are simply errors in the initial implementation, but we should give it a new pass to address both and have more correct stubs. (Some issues are not possible to fix, such as addCallabcks having multiple ParamSpec signatures in a way that mypy does not yet allow expressing.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions