[IronPython] new.classobj() fails with "TypeError: __bases__ items must be classes (got type)"

Dino Viehland dinov at exchange.microsoft.com
Thu Nov 8 00:16:18 CET 2007

This is definitely a bug in IronPython and it seems to be present in one way or another for all versions.  Thanks for the bug report.

The actual issue can be summarized as:

class foo(object): pass

class bar: pass

i = type(bar)('abc', (foo, ), {})


or an alternate way of expressing it:

class foo(object): pass

class bar: pass

type(bar).__new__(type(bar), 'abc', (foo, ), {})

Both of these should apparently be the same as type('abc', (foo, ), {}).  In other words classobj.__new__ should do the whole normal type creation thing rather than just create classobj's.

I've opened a bug to track the issue on CodePlex: http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=13740  If this is a particularly blocking issue then I'd suggest voting on the bug.  Otherwise the simple workaround is to call type() instead of new.classobj()

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of abs
Sent: Wednesday, November 07, 2007 1:33 PM
To: users at lists.ironpython.com
Subject: [IronPython] new.classobj() fails with "TypeError: __bases__ items must be classes (got type)"


Here are two files, A.py and B.py:
(Execution details follow)

--- file A.py ---
2 import sys
3 import new
4 import imp
6 def main():
7     moduleInfo = imp.find_module('B')
8     module = imp.load_module('B', moduleInfo[0], moduleInfo[1],
10    t = new.classobj('Test1', (getattr(module, 'Test'),), {})
11    i = t()
12    i.Execute()
14 if __name__ == '__main__':
15     sys.exit(main())
--- /file A.py ---

--- file B.py ---
2 class Test(object):
3     def __init__(self):
4     print 'hello'
6 def Execute(self):
7     print 'hello'
--- /file B.py ---

$ c:\Python25\python.exe A.py

$ "c:\Program Files\IronPython-1.1\ipy.exe" A.py
Traceback (most recent call last):
File C:\A.py, line 23, in Initialize
File C:\A.py, line 18, in main
TypeError: Unable to cast object of type
'IronPython.Runtime.Types.UserType' to type

$ "c:\Program Files\IronPython-2.0A5\ipy.exe" A.py
Traceback (most recent call last):
File A.py, line 23, in Initialize
File , line 0, in _stub_##19
File A.py, line 16, in main
File , line 0, in _stub_##51
TypeError: __bases__ items must be classes (got type)

Am I doing something wrong, or is this a bug?


Users mailing list
Users at lists.ironpython.com

More information about the Ironpython-users mailing list