Skip to content

Add Async classes to typing stub. #30

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

Merged
merged 1 commit into from
Dec 3, 2015
Merged

Conversation

rowillia
Copy link
Contributor

@rowillia rowillia commented Dec 1, 2015

No description provided.

@gvanrossum
Copy link
Member

This is nice, but we first need to have the corresponding classes added to the non-stub typing.py. That code is in the CPython repo but also has its own little "upstream" repo: https://github.com/ambv/typehinting -- can you submit a PR for that repo too? (The typing.py module and its test are in the src directory; there python2 backport should not get this. But the added classes should be added to the PEP text in that repo too.)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quote should include [], i.e. 'AsyncIterator[_T_co]'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rowillia
Copy link
Contributor Author

rowillia commented Dec 1, 2015

@vlasovskikh Thanks for the feedback! I was thinking the API would be:

async def f(x: int) -> Awaitable[int]:
    await asyncio.sleep(x)
    return x

Similar to Hack's syntax - http://docs.hhvm.com/manual/en/hack.async.php

Would that be workable with this implementation?

@rowillia
Copy link
Contributor Author

rowillia commented Dec 2, 2015

@gvanrossum Coorisponding typehinting PR is python/typing#168

@vlasovskikh
Copy link
Member

@rowillia This makes sense. Although python/typing#119 is still a valid request that proposes a shorter syntax.

@rowillia
Copy link
Contributor Author

rowillia commented Dec 2, 2015

@vlasovskikh totally. AFAICT that's the syntax PyCharm is using right now, right?

@vlasovskikh
Copy link
Member

@rowillia Yes, we've adopted this syntax as an experiment since there are no awaitable/coroutine types right now in the typing module.

gvanrossum added a commit that referenced this pull request Dec 3, 2015
Add Async classes to typing stub.
@gvanrossum gvanrossum merged commit d7b9c96 into python:master Dec 3, 2015
@gvanrossum
Copy link
Member

Thanks! Merged this and the typehinting changes.

@gvanrossum
Copy link
Member

(And fixed by a4c268c.)

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

Successfully merging this pull request may close these issues.

4 participants