[Python-ideas] keywording prohibited

spir denis.spir at free.fr
Sun May 3 03:16:33 CEST 2009


Le Sat, 2 May 2009 15:57:35 -0700,
Aahz <aahz at pythoncraft.com> s'exprima ainsi:

> >> How do non-keyword builtins bite?  
> > 
> > You can accidentally "re-define" or mask them (if you don't use a tool
> > that warns for that).  
> 
> Given how long it has been since the original post, I think it's unfair
> of you to cut this much context.

Sorry for this.

> What Denis Spir originally wrote was,
> "On the contrary: non-keyword builtins bite painfully!" and my rejoinder
> was written because of the extreme language.

Still, Jan's reply is the right issue I had in mind.

> Your issue is a valid one, but I have seen no cases where I would call 
> it "painful" contrasted with the pain of being unable to use a keyword
> anywhere as a name or attribute.

Depends on your pov. I consider the _possibility_ of using 'list', 'range' or 'type' as a name for totally custom thing, without even a warning, an issue, not a wishable feature. It _invents_ very hard to diagnose bugs. Painful they are. I cannot even figure out a debugging process that would point to the real source of the problem -- except for a sudden "eureka".
Actually, the issue is that precisely the non-protected build-in words are those so obvious variable names for data or funcs.
I have (painfully) learnt a reflex to use 'ranj' for range, 'Seq' for list, 'typ' for type, etc...
But maybe its me and I'm the only one ;-)

[There is an (unsatisfying) solution with some editors: just add all those word to the keyword set so that they will jump at your eyes when you pretend use them... But they also look like keywords when safely used as attributes. I would prefere a python warning mode switch.]
Strangely enough, I cannot imagine a use case for 'for' or 'in' or 'while' as names. while these ones are protected (indeed, I don't mean they shouldn't).

Denis
------
la vita e estrany



More information about the Python-ideas mailing list