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
I'd really prefer the latter style. While the result of 'foo()' is a Coroutine, this is something that type checkers will know without a hint, what really matters is the expected result of await foo() expression.
The first style is better for asyncio coroutines of Python 3.4. There is typing.Generator type in the PEP 484 parameterized with in- and out- types as well as with the return type of the generator, so the coroutine type could be an alias Coroutine = typing.Generator[Any?, Any?, V_co].
The second style is more convenient for async def functions. We could standardize the type annotation in the context of a async def to have a special meaning: it could be translated by a static checker to Coroutine[...] automatically.
I like the latter style. I'm labeling this "enhancement" because I don't want this to derail the PEP approval process. FWIW we should distinguish between the return annotation (which can be -> str) and the type of foo() (which should still be Coroutine[str]).
Now that Awaitable etc. are in typing.py, is there anything left to do in this project, or is the remaining task supporting async def etc. in mypy? That sounds like it would become fairly straightforward once the fast parser has really landed.
Or do we need language in PEP 484 itself declaring that you should write
asyncdeffoo() ->str:
return''
(referred to above as "the second style")? If you feel strongly we need PEP language then please propose some prose.
if anyone is listening to this thread, this was great for return types, but how about passing an unbound coroutine method as a parameter? From my searching it doesn't seem like there is a way to do it. It's actually a Callable[*]->Awaitable. It sounds like there should be a types.Coroutine. thanks!
Activity
vlasovskikh commentedon May 20, 2015
The first style is better for
asynciocoroutines of Python 3.4. There istyping.Generatortype in the PEP 484 parameterized with in- and out- types as well as with the return type of the generator, so the coroutine type could be an aliasCoroutine = typing.Generator[Any?, Any?, V_co].The second style is more convenient for
async deffunctions. We could standardize the type annotation in the context of aasync defto have a special meaning: it could be translated by a static checker toCoroutine[...]automatically.1st1 commentedon May 20, 2015
@vlasovskikh I agree.
We also need
typing.Awaitable[..], for cases where it is not (or cannot be) specified if we return a coroutine or a future:gvanrossum commentedon May 20, 2015
I like the latter style. I'm labeling this "enhancement" because I don't want this to derail the PEP approval process. FWIW we should distinguish between the return annotation (which can be
-> str) and the type offoo()(which should still beCoroutine[str]).1st1 commentedon Aug 3, 2015
Bumping this issue...
Definitely not a high priority one, but it would be nice if we can have Awaitable and Coroutine types in the typing module.
gvanrossum commentedon Aug 3, 2015
We will at some time, and we can add it in 3.5.1, but I'm still on vacation
and out of round tuits for another couple of weeks...
vlasovskikh commentedon Aug 4, 2015
By the way, we discussed the second style of annotating coroutines with Andrew Svetlov at EuroPython. He liked the proposal, it looked natural to him.
Wrap the return type from type providers for async function into the …
Add Async classes to typing stub.
gvanrossum commentedon Apr 29, 2016
Now that Awaitable etc. are in typing.py, is there anything left to do in this project, or is the remaining task supporting async def etc. in mypy? That sounds like it would become fairly straightforward once the fast parser has really landed.
Or do we need language in PEP 484 itself declaring that you should write
(referred to above as "the second style")? If you feel strongly we need PEP language then please propose some prose.
FWIW Larry finally announced the 3.5.2 release schedule.
ilevkivskyi commentedon May 24, 2016
I added PR #225 containing a short subsection discussing generators and coroutines in the PEP 484.
gvanrossum commentedon Jun 6, 2016
Looks like the PEP work is done here, and so are the additions to typing.py. For mypy there's a separate bug: python/mypy#706
thehesiod commentedon Oct 24, 2016
if anyone is listening to this thread, this was great for return types, but how about passing an unbound coroutine method as a parameter? From my searching it doesn't seem like there is a way to do it. It's actually a Callable[*]->Awaitable. It sounds like there should be a types.Coroutine. thanks!
ex:
ilevkivskyi commentedon Oct 24, 2016
@thehesiod Yes, and there is an issue for this #251
I hope it will be added soon.