class error

Terry Reedy tjreedy at udel.edu
Fri Mar 18 22:15:55 EDT 2011


On 3/18/2011 5:27 PM, monkeys paw wrote:
>>> TypeError: Error when calling the metaclass bases
>>> module.__init__() takes at most 2 arguments (3 given)
> OK, i overlooked that and the error was not very enlightening.

A detailed explanation: every module is an instance of a class we will 
call Module. Every class is an instance of some class, its metaclass. 
The default metaclass, in the absence of any indication otherwise, is 
class type. So your class statement was translated to

type('FileInfo',(UserDict,), d)
where d is a dict mappint '__init__' to the function object.

type.__new__ checks the types (metaclasses) of each of the base classes. 
In particular, it sees that type(UxerDict) is Module, not type. Since it 
assumed that UserDict is a class (since you said it was), it assumed 
that Module is a proper metaclass and called
   Module('FileInfo',(UserDict,), d)
But Module is not a metaclass and does not expect the tuple of base 
classes, and Module.__new__ passed too much to Module.__init__.

Since others have made the same mistake, I opened an issue to improve 
the message.
http://bugs.python.org/issue11604

-- 
Terry Jan Reedy




More information about the Python-list mailing list