[Python-ideas] relaxing keyword usage restrictions
pyideas at rebertia.com
Fri Sep 9 20:20:47 CEST 2011
On Fri, Sep 9, 2011 at 10:31 AM, Georg Brandl <g.brandl at gmx.net> wrote:
> Am 09.09.2011 09:48, schrieb Terry Reedy:
>> On 9/9/2011 2:04 AM, H Krishnan wrote:
>>> One cannot however write readable code such as the following:
>>> if yield > principal:
>>> return = yield - principal
>> Funny you should choose that example. With a slight change
>> myreturn = yield - principal
>> it is legal syntax today with 'yield' interpreted as a keyword. So it
>> cannot be interpreted as an identifier without making Python grammar
>> ambiguous and unparseable with its current parser.
> Actually, it isn't: "yield" expressions, like generator expressions, need
> to be inside parentheses. (A rule that's an ambiguousness restriction and
> a nice readability helper.)
Not always. That code is indeed valid (unless something changed in Python 3.2).
bar = yield 42 # look Ma, no parens!
a = foo()
Traceback (most recent call last):
File "prog.py", line 7, in <module>
More information about the Python-ideas