Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-27 Thread Guido van Rossum
I need to cut this debate short (too much to do already) but I'd like to press that I wish async/await to be available for general tinkering (like writing elegant parsers), not just for full fledged event loops. -- --Guido van Rossum (python.org/~guido) ___

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-26 Thread Nick Coghlan
On 27 November 2017 at 06:29, Nathaniel Smith wrote: > - In async/await, it's not obvious how to write leaf functions: > 'await' is equivalent to 'yield from', but there's no equivalent to > 'yield'. You have to jump through some hoops by writing a class with a > custom __await__ method or using @

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-26 Thread Yury Selivanov
On Sun, Nov 26, 2017 at 6:51 PM, Guido van Rossum wrote: > On Sun, Nov 26, 2017 at 12:29 PM, Nathaniel Smith wrote: [..] >> - async/await has associated thread-global state like >> sys.set_coroutine_wrapper and sys.set_asyncgen_hooks. Generally async >> libraries assume that they own these, and a

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-26 Thread Guido van Rossum
On Sun, Nov 26, 2017 at 12:29 PM, Nathaniel Smith wrote: > On Sat, Nov 25, 2017 at 3:37 PM, Guido van Rossum > wrote: > > On Sat, Nov 25, 2017 at 1:05 PM, David Mertz wrote: > >> > >> FWIW, on a side point. I use 'yield' and 'yield from' ALL THE TIME in > real > >> code. Probably 80% of those w

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-26 Thread Nathaniel Smith
On Sat, Nov 25, 2017 at 3:37 PM, Guido van Rossum wrote: > On Sat, Nov 25, 2017 at 1:05 PM, David Mertz wrote: >> >> FWIW, on a side point. I use 'yield' and 'yield from' ALL THE TIME in real >> code. Probably 80% of those would be fine with yield statements, but a >> significant fraction use `ge

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-26 Thread Guido van Rossum
On Sat, Nov 25, 2017 at 4:57 PM, Nick Coghlan wrote: > On 26 November 2017 at 02:59, Guido van Rossum wrote: > > > > I'd be happy to stop with the conclusion that we're going to rip out some > > confusing syntax rather than trying to generate code for it -- IMO we've > > proved to ourselves that

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Ethan Furman
On 11/25/2017 04:20 PM, David Mertz wrote: On Sat, Nov 25, 2017 at 3:37 PM, Guido van Rossum wrote: Maybe you didn't realize async/await don't need an event loop? Driving an async/await-based coroutine is just as simple as driving a yield-from-based one (`await` does exactly the same thing a

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Nick Coghlan
On 26 November 2017 at 02:59, Guido van Rossum wrote: > > I'd be happy to stop with the conclusion that we're going to rip out some > confusing syntax rather than trying to generate code for it -- IMO we've > proved to ourselves that this stuff is too complicated to be useful. I'll also note that

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread David Mertz
On Sat, Nov 25, 2017 at 3:37 PM, Guido van Rossum wrote: > Maybe you didn't realize async/await don't need an event loop? Driving an > async/await-based coroutine is just as simple as driving a yield-from-based > one (`await` does exactly the same thing as `yield from`). > I realize I *can*, but

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Guido van Rossum
On Sat, Nov 25, 2017 at 3:24 PM, Greg Ewing wrote: > Nick Coghlan wrote: > > def example(): >> comp1 = yield from [(yield x) for x in ('1st', '2nd')] >> comp2 = yield from [(yield x) for x in ('3rd', '4th')] >> return comp1, comp2 >> > > If the implicit "yield from" id

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Greg Ewing
Serhiy Storchaka wrote: Ivan explained that this function should be rough equivalent to def f(): t = [(yield i) for i in range(3)] return (x for x in t) This is a *rough* equivalent. There are differences in details. The details would seem to be overwhelmingly important, tho

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Guido van Rossum
On Sat, Nov 25, 2017 at 1:05 PM, David Mertz wrote: > FWIW, on a side point. I use 'yield' and 'yield from' ALL THE TIME in real > code. Probably 80% of those would be fine with yield statements, but a > significant fraction use `gen.send()`. > > On the other hand, I have yet once to use 'await',

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Greg Ewing
Nick Coghlan wrote: def example(): comp1 = yield from [(yield x) for x in ('1st', '2nd')] comp2 = yield from [(yield x) for x in ('3rd', '4th')] return comp1, comp2 If the implicit "yield from" idea seems too magical, then the other direction we could go is to make

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Yury Selivanov
On Sat, Nov 25, 2017 at 3:27 PM, Guido van Rossum wrote: > On Sat, Nov 25, 2017 at 9:21 AM, Yury Selivanov > wrote: >> >> So we are keeping asynchronous generator expressions as long as they are >> defined in an 'async def' coroutine? > > > I would be happy to declare that `await` is out of scope

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread David Mertz
FWIW, on a side point. I use 'yield' and 'yield from' ALL THE TIME in real code. Probably 80% of those would be fine with yield statements, but a significant fraction use `gen.send()`. On the other hand, I have yet once to use 'await', or 'async' outside of pedagogical contexts. There are a whole

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Guido van Rossum
> > On Sat, Nov 25, 2017 at 12:17 PM Brett Cannon wrote: > On Fri, Nov 24, 2017, 19:32 Guido van Rossum, wrote: >> >>> On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum >>> wrote: >>> The more I hear about this topic, the more I think that `await`, `yield` and `yield from` should all b

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Yury Selivanov
So we are keeping asynchronous generator expressions as long as they are defined in an 'async def' coroutine? Yury On Sat, Nov 25, 2017 at 12:17 PM Brett Cannon wrote: > > > On Fri, Nov 24, 2017, 19:32 Guido van Rossum, wrote: > >> On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum >> wrote: >

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Brett Cannon
On Fri, Nov 24, 2017, 19:32 Guido van Rossum, wrote: > On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum > wrote: > >> The more I hear about this topic, the more I think that `await`, `yield` >> and `yield from` should all be banned from occurring in all comprehensions >> and generator expressio

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Guido van Rossum
On Sat, Nov 25, 2017 at 8:07 AM, Ivan Levkivskyi wrote: > On 25 November 2017 at 16:57, Guido van Rossum wrote: > >> On Sat, Nov 25, 2017 at 6:55 AM, Ivan Levkivskyi >> wrote: >> >>> On 25 November 2017 at 04:30, Guido van Rossum wrote: >>> On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossu

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Ivan Levkivskyi
On 25 November 2017 at 16:57, Guido van Rossum wrote: > On Sat, Nov 25, 2017 at 6:55 AM, Ivan Levkivskyi > wrote: > >> On 25 November 2017 at 04:30, Guido van Rossum wrote: >> >>> On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum >>> wrote: >>> The more I hear about this topic, the more I

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Guido van Rossum
On Sat, Nov 25, 2017 at 6:55 AM, Ivan Levkivskyi wrote: > On 25 November 2017 at 04:30, Guido van Rossum wrote: > >> On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum >> wrote: >> >>> The more I hear about this topic, the more I think that `await`, `yield` >>> and `yield from` should all be ban

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Antoine Pitrou
At this point, the fact that several Python core developers fail to understand the pieces of code presented as examples should be a hint that the syntax here is far from desirable... Regards Antoine. On Sat, 25 Nov 2017 15:47:14 + Paul Moore wrote: > On 25 November 2017 at 14:55, Ivan Lev

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Paul Moore
On 25 November 2017 at 14:55, Ivan Levkivskyi wrote: > Continuing the topic of the ban, what exactly should be banned? For example > will this still be valid? > > def pack_two(): > return [(yield), (yield)] # Just a list display > > I don't see how this is controversial. It is clear t

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Ivan Levkivskyi
On 25 November 2017 at 04:30, Guido van Rossum wrote: > On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum > wrote: > >> The more I hear about this topic, the more I think that `await`, `yield` >> and `yield from` should all be banned from occurring in all comprehensions >> and generator expressi

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Serhiy Storchaka
24.11.17 00:20, Greg Ewing пише: Serhiy Storchaka wrote: Ivan explained that this function should be rough equivalent to    def f():    t = [(yield i) for i in range(3)]    return (x for x in t) This seems useless to me. It turns a lazy iterator into an eager one, which is a gross vio

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-25 Thread Serhiy Storchaka
24.11.17 02:50, Nick Coghlan пише: If we went down that path, then a list comprehension like the following:     results = [(yield future) for future in list_of_futures] might be compiled as being equivalent to:     def __listcomp_generator(iterable):     result = []     for future

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Antoine Pitrou
On Sat, 25 Nov 2017 17:10:12 +1000 Nick Coghlan wrote: > On 25 November 2017 at 16:18, Nathaniel Smith wrote: > > On Fri, Nov 24, 2017 at 9:39 PM, Nick Coghlan wrote: > >> On 25 November 2017 at 15:27, Nathaniel Smith wrote: > >>> On Fri, Nov 24, 2017 at 9:04 PM, Nick Coghlan wrote: > >>>

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Antoine Pitrou
On Sat, 25 Nov 2017 03:03:02 + MRAB wrote: > On 2017-11-25 02:21, Chris Jerdonek wrote: > > On Fri, Nov 24, 2017 at 5:06 PM, Nathaniel Smith wrote: > >> On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum > >> wrote: > >>> The more I hear about this topic, the more I think that `await`,

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nick Coghlan
On 25 November 2017 at 16:18, Nathaniel Smith wrote: > On Fri, Nov 24, 2017 at 9:39 PM, Nick Coghlan wrote: >> On 25 November 2017 at 15:27, Nathaniel Smith wrote: >>> On Fri, Nov 24, 2017 at 9:04 PM, Nick Coghlan wrote: def example(): comp1 = yield from [(yield x) for x i

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nathaniel Smith
On Fri, Nov 24, 2017 at 9:39 PM, Nick Coghlan wrote: > On 25 November 2017 at 15:27, Nathaniel Smith wrote: >> On Fri, Nov 24, 2017 at 9:04 PM, Nick Coghlan wrote: >>> def example(): >>> comp1 = yield from [(yield x) for x in ('1st', '2nd')] >>> comp2 = yield from [(yield x)

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nick Coghlan
On 25 November 2017 at 15:27, Nathaniel Smith wrote: > On Fri, Nov 24, 2017 at 9:04 PM, Nick Coghlan wrote: >> def example(): >> comp1 = yield from [(yield x) for x in ('1st', '2nd')] >> comp2 = yield from [(yield x) for x in ('3rd', '4th')] >> return comp1, comp2 > >

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nathaniel Smith
On Fri, Nov 24, 2017 at 9:04 PM, Nick Coghlan wrote: > def example(): > comp1 = yield from [(yield x) for x in ('1st', '2nd')] > comp2 = yield from [(yield x) for x in ('3rd', '4th')] > return comp1, comp2 Isn't this a really confusing way of writing def example():

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nick Coghlan
On 25 November 2017 at 13:30, Guido van Rossum wrote: > > On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum wrote: >> >> The more I hear about this topic, the more I think that `await`, `yield` and >> `yield from` should all be banned from occurring in all comprehensions and >> generator expres

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Guido van Rossum
On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum wrote: > The more I hear about this topic, the more I think that `await`, `yield` > and `yield from` should all be banned from occurring in all comprehensions > and generator expressions. That's not much different from disallowing > `return` or `b

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread MRAB
On 2017-11-25 02:21, Chris Jerdonek wrote: On Fri, Nov 24, 2017 at 5:06 PM, Nathaniel Smith wrote: On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum wrote: The more I hear about this topic, the more I think that `await`, `yield` and `yield from` should all be banned from occurring in all comp

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nick Coghlan
On 25 November 2017 at 11:04, Ivan Levkivskyi wrote: > On 25 November 2017 at 01:22, Guido van Rossum wrote: > >> The more I hear about this topic, the more I think that `await`, `yield` >> and `yield from` should all be banned from occurring in all comprehensions >> and generator expressions. T

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Chris Jerdonek
On Fri, Nov 24, 2017 at 5:06 PM, Nathaniel Smith wrote: > On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum wrote: >> The more I hear about this topic, the more I think that `await`, `yield` and >> `yield from` should all be banned from occurring in all comprehensions and >> generator expressions

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Ethan Furman
On 11/24/2017 04:22 PM, Guido van Rossum wrote: The more I hear about this topic, the more I think that `await`, `yield` and `yield from` should all be banned from occurring in all comprehensions and generator expressions. That's not much different from disallowing `return` or `break`. For m

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Yury Selivanov
On Fri, Nov 24, 2017 at 7:22 PM, Guido van Rossum wrote: > The more I hear about this topic, the more I think that `await`, `yield` and > `yield from` should all be banned from occurring in all comprehensions and > generator expressions. That's not much different from disallowing `return` > or `br

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Nathaniel Smith
On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum wrote: > The more I hear about this topic, the more I think that `await`, `yield` and > `yield from` should all be banned from occurring in all comprehensions and > generator expressions. That's not much different from disallowing `return` > or `br

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Ivan Levkivskyi
On 25 November 2017 at 01:22, Guido van Rossum wrote: > The more I hear about this topic, the more I think that `await`, `yield` > and `yield from` should all be banned from occurring in all comprehensions > and generator expressions. That's not much different from disallowing > `return` or `brea

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Guido van Rossum
The more I hear about this topic, the more I think that `await`, `yield` and `yield from` should all be banned from occurring in all comprehensions and generator expressions. That's not much different from disallowing `return` or `break`. -- --Guido van Rossum (python.org/~guido)

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Ivan Levkivskyi
OK, so my 24 hours are over :-) On 24 November 2017 at 01:50, Nick Coghlan wrote: > On 23 November 2017 at 23:04, Ivan Levkivskyi > wrote: > >> I don't see why this particular case qualifies for such a radical measure >> as an exception to syntactic rules, >> instead of just fixing it (sorry N

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-24 Thread Hrvoje Niksic
Guido van Rossum writes: And my mind boggles when considering a generator expression containing yield that is returned from a function. I tried this and cannot say I expected the outcome:    def f():        return ((yield i) for i in range(3))  

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Nick Coghlan
On 23 November 2017 at 23:04, Ivan Levkivskyi wrote: > I don't see why this particular case qualifies for such a radical measure > as an exception to syntactic rules, > instead of just fixing it (sorry Nick :-) > I've posted in more detail about this to the issue tracker, but the argument here i

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Guido van Rossum wrote: the extra scope is now part of the language definition. It can't be removed as a "bug fix". Does anyone actually rely on the scope-ness of comprehensions in any way other than the fact that it prevents local variable leakage? If not, probably nobody would notice if it w

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Guido van Rossum wrote: The debugger does stop at each iteration. It does see a local named ".0" I suppose there currently is no way for the debugger to map the variable names to what they are named in the source, right? If the hidden local were named "a.0" where "a" is the original name, ma

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Serhiy Storchaka wrote: Ivan explained that this function should be rough equivalent to def f(): t = [(yield i) for i in range(3)] return (x for x in t) This seems useless to me. It turns a lazy iterator into an eager one, which is a gross violation of the author's intent in

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Paul Moore wrote: has anyone confirmed why a function scope was considered necessary at the time of the original implementation, but it's apparently not now? At the time I got the impression that nobody wanted to spend the time necessary to design and implement a subscope mechanism. What's chan

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Guido van Rossum
On Thu, Nov 23, 2017 at 9:06 AM, Serhiy Storchaka wrote: > 23.11.17 18:08, Guido van Rossum пише: > >> This thread is still going over the speed limit. Don't commit anything >> without my explicit approval. >> > > I'm not going to write a single line of code while the decision about this > issue

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 18:08, Guido van Rossum пише: This thread is still going over the speed limit. Don't commit anything without my explicit approval. I'm not going to write a single line of code while the decision about this issue is not made. This is not easy issue. A problem with dropping the "funct

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Brett Cannon
I've now ended up in Guido's boat of needing a summary since I think this thread has grown to cover whether yield should be allowed in comprehensions, something about await in comprehensions, and now about leaking the loop variable (or some implementation detail). IOW there seems to be 3 separate d

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Guido van Rossum
This thread is still going over the speed limit. Don't commit anything without my explicit approval. I know one thing for sure. The choice to make all comprehensions functions was quite intentional (even though alternatives were also discussed) and the extra scope is now part of the language defin

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ethan Furman
On 11/23/2017 04:01 AM, Ivan Levkivskyi wrote: Lets just forget about two SO questions and dozens people who up-voted it. Questions/answers are routinely up-voted because they are well-written and/or informative, not just because somebody had a need for it or a use for the answer. The SO qu

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 15:37, Ethan Furman wrote: > On 11/22/2017 11:51 PM, Sven R. Kunze wrote: > >> A "yield" within a comprehension is like a "return" in a comprehension. It >> makes no sense at all. >> Also a "yield" and a "return with value" is also rarely seen. >> >> Comprehensions build new

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ethan Furman
On 11/22/2017 11:51 PM, Sven R. Kunze wrote: A "yield" within a comprehension is like a "return" in a comprehension. It makes no sense at all. Also a "yield" and a "return with value" is also rarely seen. Comprehensions build new objects, they are not for control flow, IMO. +1 -- ~Ethan~ __

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 15:30, Paul Moore wrote: > On 23 November 2017 at 14:24, Ivan Levkivskyi > wrote: > >> My main concern is that comprehension is not equivalent to a for loop > >> for a specific reason - the scope issue. Has anyone looked back at the > >> original discussions to confirm *wh

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 16:30, Paul Moore пише: Ok, cool. My main point still applies though - has anyone confirmed why a function scope was considered necessary at the time of the original implementation, but it's apparently not now? I'm pretty sure it was a deliberate choice, not an accident. The implementa

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 14:24, Ivan Levkivskyi wrote: >> My main concern is that comprehension is not equivalent to a for loop >> for a specific reason - the scope issue. Has anyone looked back at the >> original discussions to confirm *why* a function was used? >> >> My recollection: >> >> >>> i =

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Chris Angelico
On Fri, Nov 24, 2017 at 1:21 AM, Paul Moore wrote: > On 23 November 2017 at 13:04, Ivan Levkivskyi wrote: >> Let us forget for a moment about other problems and focus on this one: list >> comprehension is currently not equivalent to a for-loop. >> There are two options: >> - Fix this, i.e. make c

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 15:21, Paul Moore wrote: > On 23 November 2017 at 13:04, Ivan Levkivskyi > wrote: > > Let us forget for a moment about other problems and focus on this one: > list > > comprehension is currently not equivalent to a for-loop. > > There are two options: > > - Fix this, i.e.

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 13:04, Ivan Levkivskyi wrote: > Let us forget for a moment about other problems and focus on this one: list > comprehension is currently not equivalent to a for-loop. > There are two options: > - Fix this, i.e. make comprehension equivalent to a for-loop even in edge > cases

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 14:54:27 +0200 Serhiy Storchaka wrote: > 23.11.17 14:30, Antoine Pitrou пише: > > On Thu, 23 Nov 2017 14:17:32 +0200 > > Serhiy Storchaka wrote: > >> > >> I used the "yield" statement, but I never used the "yield" expressions. > >> And I can't found examples. Could you plea

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 13:45, Paul Moore wrote: > On 23 November 2017 at 12:28, Ivan Levkivskyi > wrote: > > On 23 November 2017 at 13:11, Paul Moore wrote: > >> > >> On 23 November 2017 at 12:01, Ivan Levkivskyi > >> wrote: > >> > >> > "I don't use it, therefore it is not needed" is a great

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 14:30, Antoine Pitrou пише: On Thu, 23 Nov 2017 14:17:32 +0200 Serhiy Storchaka wrote: I used the "yield" statement, but I never used the "yield" expressions. And I can't found examples. Could you please present a real-world use case for the "yield" (not "yield from") expression? Of

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 12:42, Ivan Levkivskyi wrote: >> See e.g. http://www.tornadoweb.org/en/stable/gen.html >> > > Great, so I open this page and see this code: > > results = [] > for future in list_of_futures: > results.append(yield future) > > Interesting, why don't they use a comprehensio

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
Le 23/11/2017 à 13:42, Ivan Levkivskyi a écrit : > > Great, so I open this page and see this code: > > results = [] > for future in list_of_futures: >     results.append(yield future) > > Interesting, why don't they use a comprehension for this and instead > need to invent a whole `tornado.gen.

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 12:28, Ivan Levkivskyi wrote: > On 23 November 2017 at 13:11, Paul Moore wrote: >> >> On 23 November 2017 at 12:01, Ivan Levkivskyi >> wrote: >> >> > "I don't use it, therefore it is not needed" is a great argument, >> > thanks. >> > Lets just forget about two SO question

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 13:30, Antoine Pitrou wrote: > On Thu, 23 Nov 2017 14:17:32 +0200 > Serhiy Storchaka wrote: > > > > I used the "yield" statement, but I never used the "yield" expressions. > > And I can't found examples. Could you please present a real-world use > > case for the "yield" (n

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 12:01, Ivan Levkivskyi wrote: > "I don't use it, therefore it is not needed" is a great argument, thanks. > Lets just forget about two SO questions and dozens people who up-voted it. > Do you use async comprehensions? If not, then we don't need them either. For those of u

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 14:17:32 +0200 Serhiy Storchaka wrote: > > I used the "yield" statement, but I never used the "yield" expressions. > And I can't found examples. Could you please present a real-world use > case for the "yield" (not "yield from") expression? Of course I can. "yield" express

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 13:11, Paul Moore wrote: > On 23 November 2017 at 12:01, Ivan Levkivskyi > wrote: > > > "I don't use it, therefore it is not needed" is a great argument, > thanks. > > Lets just forget about two SO questions and dozens people who up-voted > it. > > Do you use async compre

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 13:49, Antoine Pitrou пише: I'm still in favour of deprecating and then disallowing. We could disallow it without deprecation. The current behavior definitely is wrong, nobody should depend on it. It should be either fixed or disallowed. Nobody seems to have presented a real-world

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
Le 23/11/2017 à 13:01, Ivan Levkivskyi a écrit : > > "I don't use it, therefore it is not needed"  is a great argument, thanks. This is just a data point. Some people seem to think that the construct is useful for asynchronous programming. In my experience it isn't. YMMV, etc. > Lets just for

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 12:49, Antoine Pitrou wrote: > On Thu, 23 Nov 2017 12:39:46 +0100 > Ivan Levkivskyi wrote: > > > > Also I think it makes sense to keep discussion in one place, i.e. either > > here xor at https://bugs.python.org/issue10544 > > The bug tracker can be used for implementation

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 09:50:27 + Paul Moore wrote: > On 23 November 2017 at 09:14, Steve Holden wrote: > > I would urge developers, in their improvements to the language to support > > asynchronous programming, to bear in mind that this is (currently) a > > minority use case. Why the rush to se

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 12:39:46 +0100 Ivan Levkivskyi wrote: > > Also I think it makes sense to keep discussion in one place, i.e. either > here xor at https://bugs.python.org/issue10544 The bug tracker can be used for implementation discussions, but general language design decisions (such as wheth

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 10:50, Paul Moore wrote: > On 23 November 2017 at 09:14, Steve Holden wrote: > > I would urge developers, in their improvements to the language to support > > asynchronous programming, to bear in mind that this is (currently) a > > minority use case. Why the rush to set co

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 12:38, Ivan Levkivskyi wrote: > On 23 November 2017 at 11:55, Nick Coghlan wrote: > >> On 23 November 2017 at 18:11, Greg Ewing >> wrote: >> >>> Ivan Levkivskyi wrote: >>> "People sometimes want to refactor for-loops containing `yield` into a comprehension but t

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 11:55, Nick Coghlan wrote: > On 23 November 2017 at 18:11, Greg Ewing > wrote: > >> Ivan Levkivskyi wrote: >> >>> "People sometimes want to refactor for-loops containing `yield` into a >>> comprehension but that doesn't work (particularly because of the hidden >>> function

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Nick Coghlan
On 23 November 2017 at 18:11, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> "People sometimes want to refactor for-loops containing `yield` into a >> comprehension but that doesn't work (particularly because of the hidden >> function scope) - lets make it a SyntaxError" >> > > Personally I'd be

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 09:14, Steve Holden wrote: > I would urge developers, in their improvements to the language to support > asynchronous programming, to bear in mind that this is (currently) a > minority use case. Why the rush to set complex semantics in stone? +1 Also, given that languages

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Steve Holden
On Wed, Nov 22, 2017 at 8:48 PM, Sven R. Kunze wrote: > Isn't yield like a return? > ​Enough like it to make a good case, I'd say.​ > A return in a list/dict/set comprehension makes no sense to me. > ​Nor me, nor the vast majority of instance. But nowadays yield is more of a synchronisation poi

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 09:17, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> "People sometimes want to refactor for-loops containing `yield` into a >> comprehension >> > > By the way, do we have any real-life examples of people wanting to > do this? It might help us decide what the semantics sho

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 09:11, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> "People sometimes want to refactor for-loops containing `yield` into a >> comprehension but that doesn't work (particularly because of the hidden >> function scope) - lets make it a SyntaxError" >> > > Personally I'd be

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 09:15, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> On 23 November 2017 at 05:44, Greg Ewing > > wrote: >> >>def g(): >> return ((yield i) for i in range(10)) >> >> >> I think this code should be just equivalent to th

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Ivan Levkivskyi wrote: "People sometimes want to refactor for-loops containing `yield` into a comprehension By the way, do we have any real-life examples of people wanting to do this? It might help us decide what the semantics should be. -- Greg ___

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Ivan Levkivskyi wrote: On 23 November 2017 at 05:44, Greg Ewing > wrote: def g(): return ((yield i) for i in range(10)) I think this code should be just equivalent to this code def g(): temp = [(yield i) for i in range(10)]

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Ivan Levkivskyi wrote: "People sometimes want to refactor for-loops containing `yield` into a comprehension but that doesn't work (particularly because of the hidden function scope) - lets make it a SyntaxError" Personally I'd be fine with removing the implicit function scope from comprehensio

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Sven R. Kunze
On 23.11.2017 08:38, Ivan Levkivskyi wrote: I think this code should be just equivalent to this code     def g():     temp = [(yield i) for i in range(10)]     return (v for v in temp) Semantics of the comprehension should be clear here (just an equivalent for-loop without name leaking

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Ivan Levkivskyi
On 23 November 2017 at 05:44, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> The key idea is that neither comprehensions nor generator expressions >> should create a function scope surrounding the `expr` >> > > I don't see how you can avoid an implicit function scope in > the case of a generator

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Ivan Levkivskyi
On 23 November 2017 at 01:00, Yury Selivanov wrote: > On Wed, Nov 22, 2017 at 6:46 PM, Ivan Levkivskyi > wrote: > [..] > > Just found another example of intuitive behaviour: > > > async def f(): > > ... for i in range(3): > > ... yield i > > ... > async def g(): > > ...

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Tres Seaver
On 11/22/2017 07:00 PM, Yury Selivanov wrote: > I wouldn't say that it's obvious to anyone... > > I think this thread has started to discuss the use of 'yield' > expression in comprehensions, and the outcome of the discussion is > that everyone thinks that we should deprecate that syntax in 3.7,

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Stephen J. Turnbull
Greg Ewing writes: > Consider this: > > def g(): >return ((yield i) for i in range(10)) > > Presumably the yield should turn g into a generator, but... > then what? My brain is hurting trying to figure out what > it should do. I don't understand why you presume that. The ge

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Nick Coghlan
On 23 November 2017 at 15:33, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > However, my model of comprehensions is exactly a for loop that appends > to an empty list repeatedly, but doesn't leak iteration variables. Not since Python 3.0. Instead, they create a nested functi

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Stephen J. Turnbull
Paul Moore writes: > 1. List comprehensions expand into nested for/if statements in the > "obvious" way - with an empty list created to start and append used to > add items to it. >1a. Variables introduced in the comprehension don't "leak" (see below). > 2. Generator expressions expand in

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Chris Angelico
On Thu, Nov 23, 2017 at 3:36 PM, Greg Ewing wrote: > Paul Moore wrote: >> >> 3. List comprehensions are the same as list(the equivalent generator >> expression). > > > I don't think that's ever been quite true -- there have > always been odd cases such as what happens if you > raise StopIteration

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Nick Coghlan
On 23 November 2017 at 14:36, Greg Ewing wrote: > Paul Moore wrote: > >> 3. List comprehensions are the same as list(the equivalent generator >> expression). >> > > I don't think that's ever been quite true -- there have > always been odd cases such as what happens if you > raise StopIteration in

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Greg Ewing
Ivan Levkivskyi wrote: The key idea is that neither comprehensions nor generator expressions should create a function scope surrounding the `expr` I don't see how you can avoid an implicit function scope in the case of a generator expression, though. And I can't see how to make yield in a gener

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-22 Thread Greg Ewing
Paul Moore wrote: 3. List comprehensions are the same as list(the equivalent generator expression). I don't think that's ever been quite true -- there have always been odd cases such as what happens if you raise StopIteration in list(generator_expression). To my mind, these equivalences have n

  1   2   >