Error Calling Metaclass Bases
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of error when calling the metaclass bases python this site About Us Learn more about Stack Overflow the company Business
Error When Calling The Metaclass Bases Youtube
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask error when opening internet explorer Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error when calling the metaclass bases takes at most 2 arguments Error when calling the metaclass bases: function() argument 1 must be code, not str up vote 29 down vote favorite 1 I tried to subclass threading.Condition earlier today but it didn't work out. Here is the output of the Python interpreter when I try to subclass the threading.Condition class: >>> import threading >>> class ThisWontWork(threading.Condition): ... pass ... Traceback (most recent call last):
Error When Calling The Metaclass Bases Module.__init__() Takes At Most
File "
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings typeerror error when calling the metaclass bases object() takes no parameters and policies of this site About Us Learn more about Stack Overflow typeerror error when calling the metaclass bases cannot create 'nonetype' instances the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Typeerror Error When Calling The Metaclass Bases Module.__init__() Takes At Most 2 Arguments
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; http://stackoverflow.com/questions/2231427/error-when-calling-the-metaclass-bases-function-argument-1-must-be-code-not it only takes a minute: Sign up metaclass error: type.__init__() takes 1 or 3 arguments up vote 4 down vote favorite I have a metaclass: class MyMeta(type): def __init__(cls, name, bases, dct): # Do something ... return super(MyMeta, cls).__init__(cls, name, bases, dct) and a class: class MyClass(object): __metaclass__ = MyMeta When I use these I get the following error: E http://stackoverflow.com/questions/9219883/metaclass-error-type-init-takes-1-or-3-arguments TypeError: Error when calling the metaclass bases E type.__init__() takes 1 or 3 arguments What's the problem, and why does type.__init__() take a precisely variable number of arguments? python metaclass share|improve this question edited Feb 10 '12 at 0:31 asked Feb 9 '12 at 22:31 Harley Holcombe 67k125561 add a comment| 1 Answer 1 active oldest votes up vote 9 down vote accepted The problem is that in the upgrade from python 2.5 to python 2.6 type.__init__() was changed so that you are no longer required to pass in cls. So simply make the super call: return super(MyMeta, cls).__init__(name, bases, dct) Another solution is to avoid the super call altogether and do this (although it's a little less nice): return type.__init__(cls, name, bases, dct) And everything will work fine (in python >= 2.6). As to why type.__init__() can take differing numbers of arguments, check out the documentation. It's so that as well as using it as a constructor, you can call type(myobject) and it will return the type of myobject: >>> number = 1 >>> type(number) in python Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] On Tue, Apr 22, 2014 at 09:48:51AM -0400, Jorge Leon wrote: > https://mail.python.org/pipermail//tutor/2014-April/101024.html Good day, > > > I have programmed a base class for an environment I have with no problem, > but when it comes to referencing the base class's constructor in the > derived class's constructor I have been getting errors: What version of Python are you using? With super, that is actually critical. > *TypeError: Error when calling the metaclass bases* metaclass bases > * module.__init__() takes at most 2 arguments (3 given)* Read the error message. Why is it refering to *module*.__init__? My guess is that you have a module called Obstacle, and a class called Obstacle, and you have mixed them up. Maybe you are doing this: # file Obstacle.py class Obstacle: # code goes here # Another file import Obstacle class Cylinder(Obstacle) I error when calling can reproduce your error that way: py> import math py> class X(math): ... pass ... Traceback (most recent call last): File "