[IronPython] __builtins__

Sanghyeon Seo sanxiyn at gmail.com
Sat Jan 27 16:10:54 CET 2007


In CPython, __builtins__ is a module for the main script, but it is a
dictionary for modules. This is quite confusing, and this behaviour is
explicitly stated as an implementation detail. As far as I can tell,
it is always a module in IronPython.

http://docs.python.org/lib/module-builtin.html

However, far too many existing CPython sources break beacuse of this
on IronPython for my taste. The symptom is:

TypeError: <type '__builtin__'> is not enumerable

This is usually caused by well-intended codes as following:

if 'sorted' not in __builtins__:
    def sorted(seq):
        seq = seq[:]
        seq.sort()
        return seq

This lets one to keep compatibility with CPython versions before 2.4,
while still using 2.4-introduced sorted() builtin.

Here are some existing usages:
http://www.google.com/codesearch?q=%22in+__builtins__%22

-- 
Seo Sanghyeon



More information about the Ironpython-users mailing list