Re: [Python-Dev] Generator objects and list comprehensions?

2017-02-02 Thread Lukasz Langa
> On Feb 2, 2017, at 2:17 AM, Anders Munch wrote: > > Give Python 2 a little more credit. We are, it told you what your issue was: yield outside a function. Consider: >>> def f(): ... l = [(yield 1) for x in range(10)] ... print(l) >>> gen = f() >>> for i in

Re: [Python-Dev] Generator objects and list comprehensions?

2017-02-02 Thread Anders Munch
Craig Rodrigues : > Make this return a list on Python 3, like in Python 2:  [(yield 1) for x in  > range(10)]  Give Python 2 a little more credit. Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-31 Thread Nick Coghlan
On 30 January 2017 at 19:05, Brett Cannon wrote: > On Sun, 29 Jan 2017 at 16:39 Craig Rodrigues wrote: >> I'm OK with either approach. Leaving things the way they are in Python 3 >> is no good, IMHO. > > My vote is it be a SyntaxError since you're not

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-30 Thread Brett Cannon
On Sun, 29 Jan 2017 at 16:39 Craig Rodrigues wrote: > On Thu, Jan 26, 2017 at 4:09 AM, Ivan Levkivskyi > wrote: > > > > Concerning list/set/dict comprehensions, I am much more in favor of making > comprehensions simply equivalent to for-loops (more or

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-29 Thread Craig Rodrigues
On Thu, Jan 26, 2017 at 4:09 AM, Ivan Levkivskyi wrote: > > > Concerning list/set/dict comprehensions, I am much more in favor of making > comprehensions simply equivalent to for-loops (more or less like you > proposed using yield from). The only reason to introduce

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-26 Thread Ivan Levkivskyi
On 26 January 2017 at 00:53, Nathaniel Smith wrote: > > I'm not sure this is actually a good idea, given the potential for > ambiguity and backwards compatibility considerations -- I'm kind of leaning > towards the deprecate/error option on balance :-). But it's an option that >

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-25 Thread Nathaniel Smith
On Jan 25, 2017 8:16 AM, "Joe Jevnik" wrote: List, set, and dict comprehensions compile like: # input result = [expression for lhs in iterator_expression] # output def comprehension(iterator): out = [] for lhs in iterator: out.append(expression)

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-25 Thread Steve Holden
On Wed, Jan 25, 2017 at 6:28 AM, Joe Jevnik wrote: > That was a long way to explain what the problem was. I think that that > solution is to stop using `yield` in comprehensions because it is > confusing, or to make `yield` in a comprehension a syntax error. > > Thanks

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-25 Thread Sven R. Kunze
On 25.01.2017 07:28, Joe Jevnik wrote: That was a long way to explain what the problem was. I think that that solution is to stop using `yield` in comprehensions because it is confusing, or to make `yield` in a comprehension a syntax error. Same here; mixing comprehensions and yield

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-25 Thread Joe Jevnik
List, set, and dict comprehensions compile like: # input result = [expression for lhs in iterator_expression] # output def comprehension(iterator): out = [] for lhs in iterator: out.append(expression) return out result = comprehension(iter(iterator_expression)) When you

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-25 Thread Ivan Levkivskyi
On 25 January 2017 at 07:01, Chris Angelico wrote: > >>> [(yield 1) for x in range(10)] > > at 0x10cd210f8> > This is an old bug, see e.g. http://bugs.python.org/issue10544 The ``yield`` inside comprehensions is bound to the auxiliary function. Instead it should be bound to

Re: [Python-Dev] Generator objects and list comprehensions?

2017-01-24 Thread Chris Angelico
On Wed, Jan 25, 2017 at 4:38 PM, Craig Rodrigues wrote: > > Glyph pointed this out to me here: > http://twistedmatrix.com/pipermail/twisted-python/2017-January/031106.html > > If I do this on Python 3.6: > >>> [(yield 1) for x in range(10)] > at 0x10cd210f8> > > If I

[Python-Dev] Generator objects and list comprehensions?

2017-01-24 Thread Craig Rodrigues
Hi, Glyph pointed this out to me here: http://twistedmatrix.com/pipermail/twisted-python/2017-January/031106.html If I do this on Python 3.6: >> [(yield 1) for x in range(10)] at 0x10cd210f8> If I understand this: https://docs.python.org/3/reference/expressions.html#list-displays then this