Home > metaclass bases > error calling metaclass bases

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 "", line 1, in TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str Can someone explain this error? Thanks! python class inheritance metaclass share|improve this question asked Feb 9 '10 at 18:24 David Underhill 11.4k44258 add a comment| 3 Answers 3 active oldest votes up vote 46 down vote accepted You're getting that exception because, despite its class-like name, threading.Condition is a function, and you cannot subclass functions. >>> type(threading.Condition) This not-very-helpful error message has been raised on the Python bugtracker, but it has been marked "won't fix." share|improve this answer answered Feb 9 '10 at 18:31 Will McCutchen 9,95922937 Strange, I didn't think to check its type. The docs seemt o be a bit misleading then because they say (docs.python.org/library/threading.html) "class threading.Condition([lock])" which seems a bit misleading. Anyway, thanks for clearing this up :). –David Underhill Feb 9 '10 at 18:35 I see it as well when mistakenly using a module as a baseclass: class Command(main.cmdroot.list.hosts) rather than the correct Command(main.cmdroot.list.hosts.Command) –FDS Apr 29 '13 at 20:34 1 Another common c

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 "", line 1, in TypeError: module.__init__() takes at most 2 arguments (3 given) You need to say class Cylinder(Obstacle.Obstacle) Better still, use the naming convention that modules are in lowercase, and classes in CamelCase: import obstacle class Cylinder(obstacle.Obstacle): ... Even better still, Python is not Java. There is no need to put every class in its own file. > Here's how my base class' constructor looks like (position = [x, y, z]): > *class Obstacle:* > * def __init__(self,position):* > * self.position = position* In Python 2, that is a "classic class", or old-style class, and super will not work correctly. You need to inherit from object: class Obstacle(object) In Python 3, there is no difference and it should be fine. -- Steven Previous message: [Tutor] inheritance and super() function in python Next message: [Tutor] inheritance and super() function in python Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] More information about the Tutor mailing list

 

Related content

python error calling metaclass bases

Python Error Calling Metaclass Bases table id toc tbody tr td div id toctitle Contents div ul li a href Error When Calling The Metaclass Bases This Constructor Takes No Arguments a li li a href Python Error When Calling The Metaclass Bases init a li li a href Typeerror Error When Calling The Metaclass Bases Str Takes At Most Argument Given a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies relatedl of this site About Us