[Python-ideas] relaxing keyword usage restrictions

Steven D'Aprano steve at pearwood.info
Wed Sep 7 02:31:34 CEST 2011


Matt Joiner wrote:
> I was -1 until you brought up consistency. I'm going to wave the flag
> of "least surprising behaviour" and change my vote to +0. Yes it makes
> it harder to parse, but it's easier for humans :P

I see nothing "least surprising" about allowing keywords to be used as 
identifiers. I see that as causing more, not less, confusion in a 
language that allows me to write things like:

     from as import import as from
     for for in in:
         if = elif if if else else
         if break: continue
         elif continue: break

Easier for humans to parse? I don't think so. I think this is an 
anti-feature that is good for obfuscating Python code, and nothing else. 
If "consistency" is an argument in favour for allowing code like the 
above, then it's a foolish consistency.

In my opinion, we can't save this idea by only allowing keywords as 
attributes. If you want to talk about surprising behaviour, try 
explaining to a beginner why

     of = instance.of

is allowed, but

     if = instance.if

is prohibited.




-- 
Steven



More information about the Python-ideas mailing list