Open
Description
In Twisted, the Deferred class has set __await__ = __iter__
, where __iter__
is typed thusly:
def __iter__(self) -> "Deferred[_DeferredResultT]":
Deferred, insofar as it has an __iter__
method, is thus itself an Iterable
. It also implements __next__
, so is an Iterator
.
Mypy is yielding this error:
src/twisted/internet/defer.py:919:17: error: Incompatible types in assignment (expression has type "Callable[[], Deferred[_DeferredResultT]]", base class "Awaitable" defined the type as
"Callable[[], Generator[Any, None, _DeferredResultT]]") [assignment]
I suspect that perhaps Awaitable.__await__
could instead be more flexibly typed to return a Iterator[_T]
instead of a Generator[Any, None, _T]
… as that (a) seemingly works in this case and (b) the documentation for object.__await__
and PEP 492 say that it must return an iterator and not specifically a generator.
Deferred: mypy problem: #5194 (comment)