You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.)
The text was updated successfully, but these errors were encountered:
Possibly of interest: I mooted in matrix-org/synapse#15008 (comment) that Deferred should perhaps be generic over two types: the initial value fed to the first callback, and the return value of the last callback.
@DMRobertson I want to split Deferred into two protocols for that, actually, and have a thing that returns Callbackable[...] and AddCallbackable[...]. But that's a big lift :-|
The current type annotations have a number of issues:
_DeferredResultT
is contravariant, which is confusing and inaccurate; it should be invariantaddCallback
,addErrback
, andaddBoth
don't check their callbacks' signatures at all; you don't have to accept aFailure
for the latter two, to say nothing of the rest of the signature.Deferred.fromFuture
uses an unspecialized generic (see Improve type annotation fortwisted.internet.defer.Deferred.fromFuture
#11753)maybeDeferred
incorrectly returns aDeferred[Deferred[X]]
if its function returns a deferredSome 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 multipleParamSpec
signatures in a way that mypy does not yet allow expressing.)The text was updated successfully, but these errors were encountered: