Re: [Python-ideas] yield from __setitem__ and __setattr__

Hi Guido, Hi List
I think it's too soon to start inventing new syntax to address these; instead, I strongly recommend changing your APIs to use explicit method calls instead of the special syntax you so favor. Even __getitem__() returning a Future feels awkward to me (unless it's clear that the container you have in front of you is a container full of Futures). [...] But again I would like to establish asyncio as the de-factor standard for asynchronous work before trying to tweak the language more
I agree that first we need to settle a bit and look how everything works, but hey, this is python-ideas, the list for "discussing speculative language ideas".
Limiting all APIs to just use explicit method calls unfortunately leads to a very Java-like language that misses all the cool features of python. And this is not limited only to low-level stuff, but also high level interfaces. Right now I am actually working on a distributed framework, where users which are not professional programmers are supposed to write their own plugins. My boss is constantly bugging me "all that yield from stuff looks complicated, can't you just put it in a function the user calls so they don't see it anymore?" Well, as you know, I cannot. Even in the highest level of abstraction, every function that needs to do I/O has to be yielded from.
Imagine the client side of a Big Data service like google earth, what syntax do you prefer, "yield from map.get_section(long1, long2, long_step, lat1, lat2, lat_step)", or simply "yield from map[long1:long2:long_step, lat1:lat2:lat_step]"?
Until now, a yield from was just a rather rare case used only on special occasions. But once asyncio becomes more wide spread, it will simply be everywhere. It will be so ubiquitous that I even thought it should not be spelled out anymore at all - every expression evaluating to a coroutine should automatically be yielded from. But that would actually kill the advantange of this construct - the cooperative multitasking we are doing with yield from. The programmer of a piece of code would not know anymore where other tasks step in, so all the problems with race conditions re-appear.
Given that it will be used very often in the future, I thought we could even use a special character to represent the yield from, say, a $. Then code like the following would be possible, please don't hate me for the Perl-look:
for a, $b, c in some_iterator(): $ob.foo = $calculate(a + b, c)
which would be equivalent to
for a, _b, c in some_iterator(): b = yield from _b yield from ob.__setattr__("foo", yield from calculate(a + b, c))
But I guess with that I am just way too speculative...
Greetings
Martin

On 10 Sep 2014 19:41, "Martin Teichmann" lkb.teichmann@gmail.com wrote:
Hi Guido, Hi List
I think it's too soon to start inventing new syntax to address these;
instead, I strongly
recommend changing your APIs to use explicit method calls instead of
the special
syntax you so favor. Even __getitem__() returning a Future feels
awkward to me
(unless it's clear that the container you have in front of you is a
container full of Futures).
[...] But again I would like to establish asyncio as the de-factor standard
for asynchronous work
before trying to tweak the language more
I agree that first we need to settle a bit and look how everything works, but hey, this is python-ideas, the list for "discussing speculative language ideas".
Limiting all APIs to just use explicit method calls unfortunately leads to a very Java-like language that misses all the cool features of python. And this is not limited only to low-level stuff, but also high level interfaces. Right now I am actually working on a distributed framework, where users which are not professional programmers are supposed to write their own plugins. My boss is constantly bugging me "all that yield from stuff looks complicated, can't you just put it in a function the user calls so they don't see it anymore?" Well, as you know, I cannot. Even in the highest level of abstraction, every function that needs to do I/O has to be yielded from.
The local visibility of the asynchronous flow control is deliberate. Folks that don't want that behaviour to be visible in user level code have the option of using gevent as a synchronous to asynchronous adapter to provide a developer experience that is closer to the pre-emptive multithreading many folks are used to working with.
For a couple of longer discussions of some of the trade-offs involved in adopting that more implicit approach, you may want to take a look at my post at http://python-notes.curiousefficiency.org/en/latest/pep_ideas/async_programm... as well as Glyph's at https://glyph.twistedmatrix.com/2014/02/unyielding.html
Regards, Nick.

On 10 Sep 2014 23:43, "Nick Coghlan" ncoghlan@gmail.com wrote:
The local visibility of the asynchronous flow control is deliberate.
My apologies, I initially missed the part of your email where you made it clear you already understood those benefits.
In that case, I agree that a shorter (perhaps even symbolic) spelling may make sense some day, but also agree with Guido that it's way too soon to be making further changes in this area. asyncio hasn't even graduated from provisional status yet :)
Cheers, Nick.
participants (2)
-
Martin Teichmann
-
Nick Coghlan