A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2015-May/139785.html below:

[Python-Dev] PEP 492 and types.coroutine

[Python-Dev] PEP 492 and types.coroutine [Python-Dev] PEP 492 and types.coroutineYury Selivanov yselivanov.ml at gmail.com
Sat May 2 19:41:18 CEST 2015
On 2015-05-02 1:04 PM, Ethan Furman wrote:
> According to https://www.python.org/dev/peps/pep-0492/#id31:
>
>    The [types.coroutine] function applies CO_COROUTINE flag to
>    generator-function's code object, making it return a coroutine
>    object.
>
> Further down in https://www.python.org/dev/peps/pep-0492/#id32:
>
>     [await] uses the yield from implementation with an extra step of
>     validating its argument. await only accepts an awaitable,
>     which can be one of:
>
>       ...
>
>       - A generator-based coroutine object returned from a generator
>         decorated with types.coroutine().
>
> If I'm understanding this correctly, type.coroutine's only purpose is to add
> a flag to a generator object so that await will accept it.
>
> This raises the question of why can't await simply accept a generator
> object?  There is no code change to the gen obj itself, there is no
> behavior change in the gen obj, it's the exact same byte code, only a
> flag is different.
>

Because we don't want 'await' to accept random generators.
It can't do anything meaningful with them, in a world where
all asyncio code is written with new syntax, passing generator
to 'await' is just a bug.

'types.coroutine' is something that we need to ease transition
to the new syntax.

Yury
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4