[Python-Dev] [poll] New name for __builtins__
Terry Reedy
tjreedy at udel.edu
Fri Nov 30 00:12:53 CET 2007
"Guido van Rossum" <guido at python.org> wrote in message
news:ca471dc20711290954v173cf2ebx9427de211ba9afbd at mail.gmail.com...
| But then I thought, what if we renamed the __builtin__ module instead
| to builtins, and left __builtins__ alone?
|
| In Python 0.1, __builtin__ *was* called builtin, and I think the
| reason for renaming it wasn't particularly well thought-out; as a
| *module*, I'm not sure that it really needs to have such a special
| name (I don't think it's more special than sys, anyway). There's no
| motivation in the checkin comment that renamed it (r3527).
+1 for plain 'builtins' or whatever for the name of the module. I believe
it would have been less confusing to me learning Python, (and still today
;-) if it had been this way 10 years ago.
The rationale for special __xxx__ names (identifiers) is to avoid namespace
clashes. So they are only needed for namespace names bound to objects,
including string objects representing definition names. Since
'__builtin__' is merely a string object bound to '__name__' (I presume) in
the module itself and to '__builtins__' in all others, a string that did
not imitate a reserved identifier would be clearer, at least to me.
Similarly, by the way, the main module might justifiably be '__name__'ed
'main' rather than '__main__' since whatever string is bound to '__name__'
is *not* in the module namespace. "if __name__ == 'main' " is a bit easier
to type and to me a bit clearer. The only problem would be if someone put
the incantation into a non-main module named 'main.py', but the same is
true today of '__main__.py'. And I would consider either a buggy practice.
These are the only two builtin strings I can think of that have the form of
special names, even though they are not actually identifiers. If so, they
are the only two 'special names' that *must* be quoted as strings, while
binding names (identifiers) usually are not. If both were changed, then
'special names' would simply be 'internal namespace names used by the
implementation'. I think this would make it easier for beginners to keep
separate the notions of 'identifier' and 'string'.
Terry Jan Reedy
More information about the Python-Dev
mailing list