[IronPython] __builtins__

Dino Viehland dinov at exchange.microsoft.com
Mon Jan 29 21:53:10 CET 2007


Thanks for reporting this bug.  I've opened CodePlex bug #7766 (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=7766).

There's some other weird behavior I was looking at for __builtins__ last week and maybe this will turn out to be related.  Redefining __builtins__ at the console changes the behavior of import (e.g. import sys will fail if __builtins__ doesn't have __import__ defined on it) but this doesn't work at the module level.  I'll need to dig deeper to see if there's some dependency of this being a dictionary or a module but it is interesting.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Sanghyeon Seo
Sent: Saturday, January 27, 2007 7:11 AM
To: Discussion of IronPython
Subject: [IronPython] __builtins__

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
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list