Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51749

Re: Oddity with 'yield' as expression - parentheses demanded

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'say,': 0.05; 'assignment': 0.07; 'expressions': 0.07; "subject:' ": 0.07; 'adopted': 0.09; 'consistency': 0.09; 'statements': 0.09; '(x,': 0.16; 'backward': 0.16; 'bind': 0.16; 'brackets:': 0.16; 'comma.': 0.16; 'expression,': 0.16; 'expression.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'governed': 0.16; 'preserve': 0.16; 'semantically': 0.16; 'subject:expression': 0.16; 'subject:yield': 0.16; 'tuple': 0.16; 'wrote:': 0.18; '(not': 0.18; 'bit': 0.19; 'basically': 0.19; 'normally': 0.19; 'thu,': 0.19; 'meant': 0.20; 'written': 0.21; '(in': 0.22; 'aug': 0.22; 'rules': 0.22; 'right.': 0.26; 'header :In-Reply-To:1': 0.27; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'equivalent.': 0.31; 'probably': 0.32; 'could': 0.34; 'subject:with': 0.35; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'right?': 0.36; 'yield': 0.36; 'being': 0.38; 'needed': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'catch': 0.60; 'expression': 0.60; 'ian': 0.60; 'became': 0.64; 'places': 0.64; 'more': 0.64; 'as:': 0.81; 'is)': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=IoP4l9NpOM2vUlnFoCxXND6D9IDDVKZ3uLkFRMlHClI=; b=t5PcJJWWM0S5iEC1Lo73kSBdqoxbDKn2wepMrvwMSG0X8yxJqwut00nr2fh1CgaPtk yUzYAY9FR0TjRLREUJqmipmSrn5J7OqKRHZGr4OhV3Wr/ZvMglAH71iHAqji8HZEivOm 11xhfHm3cZU4MlCwmfCawsiFKsau7lHrncuIX5BXXb+DZGti2UwIESCKOxhq9GdoeP6Q BEZGcf2hK/xjpFuQFHe/MbpWP8XJiBI2bsw5HoF6cUQ8pQchhnBiN2hKb1LlWFcIAhCC l0JCtTAGK7zS0M0dmVZxYRCANjJ8Pnq11j86xT+LneLq2x3lSUw4v7sgQaCM+6lwRV2D 84hA==
MIME-Version 1.0
X-Received by 10.220.169.146 with SMTP id z18mr821000vcy.80.1375379913064; Thu, 01 Aug 2013 10:58:33 -0700 (PDT)
In-Reply-To <CALwzidm=afnn=nHgzp9Ru=7eJQmH=zE8JGX+-9O2k8SAYfdvUw@mail.gmail.com>
References <CAPTjJmoCj40Gbktu-0Tkos_toTWvPJ8_0r61FC9wU0GA9gMDMw@mail.gmail.com> <CALwzidm=afnn=nHgzp9Ru=7eJQmH=zE8JGX+-9O2k8SAYfdvUw@mail.gmail.com>
Date Thu, 1 Aug 2013 18:58:33 +0100
Subject Re: Oddity with 'yield' as expression - parentheses demanded
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.85.1375379916.1251.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375379916 news.xs4all.nl 15982 [2001:888:2000:d::a6]:33280
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51749

Show key headers only | View raw


On Thu, Aug 1, 2013 at 6:35 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> yield was a statement before it became an expression, and the syntax
> "yield x, y, z" was (and still is) perfectly legal, with all three
> expressions (technically a single tuple expression) being governed by
> the yield.  That is to say, "yield x, y, z" and "yield (x, y, z)" are
> semantically equivalent.  When it became an expression, in order to
> preserve this equivalence, that meant that the yield expression needed
> to bind even less tightly than the comma.  In terms of the grammar,
> yield needed to take an expression_list, not just an expression.
>
> There are only three places in the grammar where expression_lists are
> used without enclosing them in brackets:  expression statements (in
> this case analogous to the yield statement), the return statement (not
> normally used to return a value in a generator), and the assignment
> statements.  So for consistency and clarity the rules for
> parenthesizing yield statements are basically adopted from the
> existing rules for parenthesizing expression_lists.

Ahh, right. That makes good sense.

If this were being created anew now, would yield be made to bind more
tightly than the comma? That would mean that

yield x, y, z    # Yield a tuple

would need to be written as:

yield (x, y, z)

which wouldn't, in my opinion, be a bad thing. (It'd probably catch a
few people out, but a linter could notice that a tuple is being
created and ignored.) So this is a bit of a wart, but it's for
backward compatibility. Right?

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Oddity with 'yield' as expression - parentheses demanded Chris Angelico <rosuav@gmail.com> - 2013-08-01 18:58 +0100

csiph-web