| Store | Cart

Re: [Python-Dev] PEP 492: No new syntax is required

From: Yury Selivanov <ysel...@gmail.com>
Sun, 26 Apr 2015 16:40:03 -0400
Hi Mark,

On 2015-04-26 4:21 PM, Mark Shannon wrote:
> Hi,>> I was looking at PEP 492 and it seems to me that no new syntax is > required.

Mark, all your points are explained in the PEP in a great detail:

>> Looking at the code, it does four things; all of which, or a > functional equivalent, could be done with no new syntax.

Yes, everything that the PEP proposes can be done without new syntax.  
That's how people use asyncio right now, with only what we have in 3.4.

But it's hard.  Iterating through something asynchronously?  Write a 
'while True' loop.  Instead of 1 line you now have 5 or 6.  Want to 
commit your database transaction?  Instead of 'async with' you will 
write 'try..except..finally' block, with a very high probability to 
introduce a bug, because you don't rollback or commit properly or 
propagate exception.

> 1. Make a normal function into a generator or coroutine. This can be > done with a decorator.

https://www.python.org/dev/peps/pep-0492/#rationale-and-goals
https://www.python.org/dev/peps/pep-0492/#debugging-features
https://www.python.org/dev/peps/pep-0492/#importance-of-async-keyword

> 2. Support a parallel set of special methods starting with 'a' or > 'async'. Why not just use the current set of special methods?

Because you can't reuse them.

https://www.python.org/dev/peps/pep-0492/#why-not-reuse-existing-for-and-with-statements
https://www.python.org/dev/peps/pep-0492/#why-not-reuse-existing-magic-names

> 3. "await". "await" is an operator that takes one argument and > produces a single result, without altering flow control and can thus > be replaced by an function.

It can't be replaced by a function. Only if you use greenlets or 
Stackless Python.

> 4. Asynchronous with statement. The PEP lists the equivalent as "with > (yield from xxx)" which doesn't seem so bad.

There is no equivalent to 'async with'. "with (yield from xxx)" only 
allows you to suspend execution
in __enter__ (and it's not actually in __enter__, but in a coroutine 
that returns a context manager).

https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-async-with 
see "New Syntax" section to see what 'async with' is equivalent too.

>> Please don't add unnecessary new syntax.


It is necessary.  Perhaps you haven't spent a lot of time maintaining 
huge code-bases developed with frameworks like asyncio, so I understand 
why it does look unnecessary to you.

Thanks,
Yury

_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Mark Shannon Apr 26, 2015 08:21 pm
yoav glazner Apr 26, 2015 08:26 pm
Yury Selivanov Apr 26, 2015 08:40 pm
Mark Shannon Apr 26, 2015 09:48 pm
Brett Cannon Apr 26, 2015 10:09 pm
Yury Selivanov Apr 26, 2015 10:16 pm
Yury Selivanov Apr 26, 2015 10:12 pm
Nick Coghlan Apr 26, 2015 10:24 pm
Mark Shannon Apr 27, 2015 08:09 am
Paul Sokolovsky Apr 26, 2015 10:25 pm
Yury Selivanov Apr 26, 2015 10:49 pm
Paul Sokolovsky Apr 26, 2015 11:32 pm
Yury Selivanov Apr 26, 2015 11:45 pm
Paul Sokolovsky Apr 27, 2015 12:17 am
Yury Selivanov Apr 27, 2015 12:39 am
Paul Sokolovsky Apr 27, 2015 10:48 pm
Glenn Linderman Apr 28, 2015 04:46 pm
Guido van Rossum Apr 26, 2015 11:13 pm
Paul Sokolovsky Apr 26, 2015 11:50 pm
Mark Shannon Apr 27, 2015 07:48 am
Stefan Behnel Apr 28, 2015 06:51 pm
Guido van Rossum Apr 28, 2015 08:00 pm
Paul Sokolovsky Apr 28, 2015 07:24 pm
Mark Shannon Apr 28, 2015 07:59 pm
Paul Sokolovsky Apr 28, 2015 09:14 pm
Messages in this thread