[Python-ideas] relaxing keyword usage restrictions

Devin Jeanpierre jeanpierreda at gmail.com
Fri Sep 9 20:24:21 CEST 2011


Even so, there's the difference between (yield) - principal and yield
(- principal)

Devin

On Fri, Sep 9, 2011 at 2:20 PM, Chris Rebert <pyideas at rebertia.com> wrote:
> 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:
> <snip>
>>>> 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).
>
> Python 3.1.2:
>
> def foo():
>    bar = yield 42 # look Ma, no parens!
>    print(bar)
>
> a = foo()
> print(next(a))
> a.send(7)
>
> Output:
> 42
> 7
> Traceback (most recent call last):
>  File "prog.py", line 7, in <module>
>    a.send(7)
> StopIteration
>
> Cheers,
> Chris
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list