TypeError: Error when calling the metaclass bases a new-style class can't have only classic bases
Asked Answered
C

2

11

A collection of classes defined as:

class A():
    @staticmethod
    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 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?

Commodore answered 13/3, 2012 at 1:27 Comment(0)
C
18

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 keep seeing them on stackoverflow and everywhere. Why, oh why?

Coyle answered 13/3, 2012 at 1:37 Comment(0)
P
0

For my case, I tried depreciating the version of the package. It worked !

Second trial, this was there in python 2 due to version issues. Upgrade your code to python3. It works.

Powwow answered 6/9, 2021 at 13:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.