[Python-Dev] [poll] New name for __builtins__

Guido van Rossum guido at python.org
Fri Nov 30 00:34:27 CET 2007


On Nov 29, 2007 3:12 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> "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.

Right. It was this way 15 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.

Right again.

> 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.

Not quite. main.py is a valid regular module name and shouldn't be
endowed with special powers. But __main__.py would be a "reserved"
module name, like __init__.py, and could reasonably be expected to
have extra semantics.

> 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.

I'm not sure I follow. A module name is an identifier too. (This is
how it's used by import.)

> 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'.

I think you're looking at this from the wrong angle.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list