Skip to content

Wrong interface for AsyncIterable #1396

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

Closed
ask opened this issue Jun 7, 2017 · 3 comments
Closed

Wrong interface for AsyncIterable #1396

ask opened this issue Jun 7, 2017 · 3 comments

Comments

@ask
Copy link
Contributor

ask commented Jun 7, 2017

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 :-)

@ask ask changed the title Wrong interface for AsyncIterable and AsyncIterator Wrong interface for AsyncIterable Jun 7, 2017
ask added a commit to robinhood/faust that referenced this issue Jun 7, 2017
@gvanrossum
Copy link
Member

gvanrossum commented Jun 8, 2017 via email

@ask
Copy link
Contributor Author

ask commented Jun 9, 2017

I have the fix already and I could easily submit a PR, but I'm not sure where the tests go?

Would I add these tests to mypy perhaps? The test instructions mention running the mypy tests.

I will try to think of a code fragment also, but is not _collections_abc the canonical reference here:

https://github.com/python/cpython/blob/2e9cd5825c5ccdbb6f65a57c0c7941078e003c14/Lib/_collections_abc.py#L158-L170

There AsyncIterable has __aiter__, (no __anext__ as typeshed has as the only method),

@gvanrossum
Copy link
Member

There is no convenient place to put the tests, I just want you to show the test code you ran manually to demonstrate that there is code that works at runtime but that is wrongly rejected by Python, to support this issue. You can put it in the introduction for the PR you submit. (Also link to this issue of course.)

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

No branches or pull requests

2 participants