Skip to content

Wrong interface for AsyncIterable #1396

@ask

Description

@ask

In mypy AsyncIterable has an __anext__ method, but it should not: it should have __aiter__ only, but that is missing.

The code here:

class AsyncIterable(Generic[_T_co]):
@abstractmethod
def __anext__(self) -> Awaitable[_T_co]: ...
class AsyncIterator(AsyncIterable[_T_co],
Generic[_T_co]):
@abstractmethod
def __anext__(self) -> Awaitable[_T_co]: ...
def __aiter__(self) -> 'AsyncIterator[_T_co]': ...

Should be:

class AsyncIterable(Generic[_T_co]):
    @abstractmethod
    def __aiter__(self) -> 'AsyncIterator[_T_co]': ...

class AsyncIterator(AsyncIterable[_T_co],
                    Generic[_T_co]):
    @abstractmethod
    def __anext__(self) -> Awaitable[_T_co]: ...
    def __aiter__(self) -> 'AsyncIterator[_T_co]': ...

I will try to figure out how to contribute a patch and tests :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions