Single type for __builtins__ in Py3.0

Collin Winter collinw at gmail.com
Fri Sep 23 10:55:58 EDT 2005


Hallo all,

As it currently stands, the type of the global __builtins__ differs
depending on whether you're in the __main__ namespace (__builtins__ is
a module) or not (its a dict). I was recently tripped up by this
discrepancy, and googling the issue brings up half-a-dozen or so c.l.p
threads where others have been bitten by this, too.

I'd like to propose that in Py3.0 (if not earlier), __builtins__ will
be the same type regardless of which namespace you're in. Tim Peters
has said [1] that the reason __builtins__ in __main__ is a module so
that "the curious don't get flooded with output when doing vars() at
the prompt". Based on this, I propose that __builtins__ be a module
(really, an alias for the __builtin__ module as it is now) in all
namespaces.

If possible, I'd like to see this go in before 3.0. The reference
manual currently states [2] that __builtins__ can be either a dict or
a module, so changing it to always be a module would still be in
keeping with this. However, I realise that there's probably code out
there that hasn't been written to deal with both types, so this would
result in some minor breakage (though it would be easily fixable).

If this gets a good response, I'll kick it up to python-dev.

Thanks,
Collin Winter

[1] http://mail.python.org/pipermail/python-list/2002-May/103613.html
[2] http://www.python.org/doc/2.4.1/ref/naming.html



More information about the Python-list mailing list