Error When Calling The Metaclass Bases Cannot Create Builtin_function_or_method Instances
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 this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation 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; it only takes a minute: Sign up Python - subclass open? up vote 1 down vote favorite Is is possible to subclass python's built-in open? I am intermittently getting the following error: class Open(open): pass x = mymodule.Open() TypeError: Error when calling the metaclass bases cannot create 'builtin_function_or_method' instances The python python-2.7 subclass share|improve this question asked Dec 30 '12 at 23:49 Jzl5325 1,31011732 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepted The open is not a class, it is a function. However, the file object is a type that you can subclass. type(open) # OUT:
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 this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation 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; it only takes a minute: Sign up TypeError: Error when calling the metaclass bases a new-style class can't have only classic bases up vote 8 down vote favorite A collection of classes defined as: class A(): @staticmethod http://stackoverflow.com/questions/14095909/python-subclass-open def call(): print('a') class C(type): def __repr__(self): return 'somename' class B(A): __metaclass__ = C @staticmethod def call(): print('b') def boundcall(self): print('bound') When run, gives this error: TypeError: Error when calling the metaclass bases a new-style class can't have only classic bases I need the metaclass (I think) to have a known string representation of B in my code. Reason for having that is beside the point but it'll greatly help with future updates. So assuming I need C http://stackoverflow.com/questions/9677163/typeerror-error-when-calling-the-metaclass-bases-a-new-style-class-cant-have-o to be the metaclass of B and B will be a subclass of A can someone tell me what is going wrong here and how I might change what I'm doing to remove the error? python oop typeerror new-style-class share|improve this question edited Dec 21 '14 at 3:28 bignose 10k63561 asked Mar 13 '12 at 1:27 rutherford 3,011113065 add a comment| 1 Answer 1 active oldest votes up vote 12 down vote accepted The problem is the line class A(): It should be: class A(object): That way, you make A a new style class. The empty parens make no sense whatsoever, and still, I continue to see them on stackoverflow and everywhere. Why, oh why? share|improve this answer answered Mar 13 '12 at 1:37 pillmuncher 6,52221926 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged python oop typeerror new-style-class or ask your own question. asked 4 years ago viewed 15011 times active 1 year ago Related 603What is the difference between old style and new style classes in Python?2Python new-style-class-related question30Why isn't __new__ in P
tips & solutions https://bytes.com/topic/python/answers/725401-unable-inherit from a community of 418,547 IT Pros & Developers. It's quick & easy. unable to inherit P: 5 MisterPete I've run into https://mail.python.org/pipermail/python-list/2005-February/345058.html this issue a couple of times. I want to inherit from a class in order to extend it's functionality. The problem is error when that the class is defined in c in a shared library and doesn't seem to be designed so that it will allow inheritance (no __class__ defined, etc). For example the Client object from pysvn. Expand|Select|Wrap|Line Numbers importpysvn classMyClient(pysvn._pysvn._Client): pass Traceback (most recent call error when calling last): File "
distribution Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Kent Johnson wrote: > Is it possible to subclass cElementTree.Element? I tried > >>> import cElementTree as et > >>> class Elt(et.Element): > ... pass > ... > Traceback (most recent call last): > File "