Single type for __builtins__ in Py3.0

Collin Winter collinw at gmail.com
Fri Sep 23 19:16:59 EDT 2005


On 9/23/05, Peter Hansen <peter at engcorp.com> wrote:
> User are clearly told in various places that names with leading and
> trailing double underscores are *special*, and at least by implication
> they are not to be used without a good understanding of what they are.
> You certainly shouldn't have found any docs telling you to use
> __builtins__ that way.
>
> http://www.google.ca/search?q=site%3Apython.org+__builtin__ is a pretty
> quick way of finding the above docs, and while doing the same search
> with __builtins__ admittedly finds lots of mailing list archives where
> people have the same misconception as you did, it doesn't take one past
> the second page of results before you'll be right back at a post by
> Fredrik pointing out the same mistake. :-)

The difference between __builtins__ and the other __*__ names is that
while the others shouldn't be used without understanding their
purpose, the consensus on __builtins__ seems to be that it shouldn't
be used at all. Since you mention Fredrik's posts on the subject, I'll
quote one for you:

http://mail.python.org/pipermail/python-list/2002-June/109090.html
"""
forget about __builtins__; it's an implementation detail.

if you need to explicitly refer to stuff in the built-in namespace,
*always* import the __builtin__ module.  never use __builtins__
in your code.
"""

Other posts echo this. To my mind this indicates that, at the very
least, users should be explicitly told -- up front, in the official
documentation --  that they shouldn't ever touch __builtins__. Maybe
__builtins__ could be removed entirely from Py3.0, thus bringing
reality in to sync with policy.

Collin Winter



More information about the Python-list mailing list