(original) (raw)

On 22 November 2017 at 17:16, Paul Moore <p.f.moore@gmail.com> wrote:
On 22 November 2017 at 16:08, Ivan Levkivskyi <levkivskyi@gmail.com> wrote:
\> On 22 November 2017 at 16:56, Yury Selivanov <yselivanov.ml@gmail.com>
\> wrote:
\>>
\>> On Wed, Nov 22, 2017 at 10:10 AM, Ivan Levkivskyi <levkivskyi@gmail.com>
\>> wrote:
\>> > On 22 November 2017 at 15:47, Paul Moore <p.f.moore@gmail.com> wrote:
\>> \[...\]
\>> I'm all for prohibiting using 'yield' expression in generator
\>> expressions or comprehensions. The semantics is way to hard to
\>> understand and hence be of any value.
\>>
\>> Making 'await' a SyntaxError is absolutely not an option. Async
\>> generator expressions are a shorthand syntax for defining asynchronous
\>> generators (PEP 525), and it's already being used in the wild.
\>
\>
\> OK, makes sense, so it looks like we may have the following plan:
\>
\> - fix \`yield\` in comprehensions

I'm still not clear what "fix" would actually mean, but you propose
clarifying the docs below, so I assume it means "according to whatever
the updated docs say"...


I mean the initial proposal: make comprehensions equivalent to a for-loop
\> - update PEP 530 and docs re generator expressions vs comprehensions

Docs more importantly than PEP IMO. And are you implying that there's
a difference between generator expressions and comprehensions? I
thought both were intended to behave as if expanded to a function
containing nested for loops? Nothing said in this thread so far (about
semantics, as opposed to about current behaviour) implies there's a
deliberate difference.

I think there may be a difference:

comprehension \`g = \[(yield i) for i in range(3)\]\` is defined as this code:

\_\_result = \[\]
\_\_i = None
try:
for \_\_i in range(3):
\_\_result.append(yield \_\_i)
g = \_\_result
finally:
del \_\_result, \_\_i

while \`g = list((yield i) for i in range(3))\` is defined as this code:

def \_\_gen():
for i in range(3):
yield (yield i)
g = list(\_\_gen())

Although these two definitions are equivalent in simple cases (like having \`f(i)\` instead of \`yield i\`)

But this is debatable, I think before we move to other points we need to agree on the clear definitions of semantics of generator expressions and comprehensions.

--
Ivan