[Python-ideas] relaxing keyword usage restrictions

Georg Brandl g.brandl at gmx.net
Fri Sep 9 19:31:59 CEST 2011

Am 09.09.2011 09:48, schrieb Terry Reedy:
> On 9/9/2011 2:04 AM, H Krishnan wrote:
>> Hi,
>> I have read through the comments and the (largely negative) votes for
>> this idea.
>> The main argument against it seems to be readability. I feel the
>> examples I chose were distracting. The intent of the examples was to
>> show the semantics and not to suggest that anyone should write such
>> code.
> The parser has to be ready for and work correctly with the worst horror 
> anyone *could* write.
>    if in in in or and and and:
> One can write totally unreadable code even with the current syntax:
>> if not was is can:
>>     return take
> Except that *is* readable *because* keywords are keywords and 
> identifiers are identifiers. 'if not x is y' implies that x and y should 
> be boolean values and we want them to have opposite values to proceed.
>> 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.)


More information about the Python-ideas mailing list