Steven D'Aprano wrote:
> The interpreter should infer that a plain `def` function is actually
an `async def` from the presence of `async yield`, similar to the way
the interpreter infers that a plain `def` function is actually a
generator from the presence of a `yield`.

I would have to strongly disagree with this part of the author's proposal
especially. The whole purpose of the `async def` declaration was to help
ensure that a normal subroutine function was not mistakenly used as a
coroutine. Allowing the interpreter to infer that a regularly declared
function is actually a subroutine would ultimately go against this
intention by making the distinction between subroutines and coroutines far
less explicit.

Steven D'Aprano wrote:
> What if you're not using asyncio, but some other framework?

This point is also especially important. The "async/await" syntax was meant
to essentially be its own separate API of sorts, to allow for the usage of
entirely distinct async frameworks such as curio. Asyncio is dependent on
the "async/await" syntax, but not the other way around. I'm not certain
that I understand how these changes could be applied without causing
compatibility issues.

On Sun, Sep 15, 2019 at 8:52 PM Steven D'Aprano <st...@pearwood.info> wrote:

> On Mon, Sep 16, 2019 at 11:36:45AM +1200, Greg Ewing wrote:
> > George Fischhof wrote:
> > >With this syntax the use / programmer do not have to write async def,
> > >nor await, because after the yield the await should come automatically.
> >
> > I don't see how you can eliminate the await in your example generator.
> > Can you show us how it would look in its entirety under your proposal?
>
> I think the proposal is for two things:
>
> 1. `async yield i` to be syntactic sugar for `yield i; await
> asyncio.sleep(delay)`.
>
> 2. The interpreter should infer that a plain `def` function is actually
> an `async def` from the presence of `async yield`, similar to the way
> the interpreter infers that a plain `def` function is actually a
> generator from the presence of a `yield`.
>
>
>     # Original
>     async def ticker(delay, to):
>         """Yield numbers from 0 to to every delay seconds."""
>         for i in range(to):
>             yield i
>             await asyncio.sleep(delay)
>
>
>     # Re-written
>     def ticker(delay, to):
>         """Yield numbers from 0 to to every delay seconds."""
>         for i in range(to):
>             async yield i
>
>
> So you save one line and perhaps 25-30 key presses when writing the
> function, at the cost of making it much less clear what's going on when
> reading the function.
>
> How does it known how long to sleep?
>
> What if you're not using asyncio, but some other framework?
>
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/KKAAH3S4LM52NL5572LAY5QMHYUUUN7T/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TZKXEGXZUQJL57IWKMKVQUEADTQNURXJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to