I'm debugging a python script (python isn't my go to language), and this is the first time I'm working with metaclass's in python. I'm getting a metaclass conflict error when I run the code as it is below.
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
In attempting to solve it I commented out the metaclass declaration in MySQLMSoftware, thinking that it's redundant as it inherits from a class with the same metaclass declaration, but this leads to:
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
Any insight, guidance or direction would be greatly appreciated. I've been reading about python's metaclass implementation and the issue isn't popping out so far.
MSoftware.py
from abc import ABCMeta, abstractmethod
class MSoftware(object) :
__metaclass__ = ABCMeta
def __init__(self,name,spark=None,mysql=None):
self.name = name
...
MySQLMSoftware.py
from mouse import Mouse, MSoftware
from abc import ABCMeta, abstractmethod
class MySQLMSoftware(MSoftware): # Traceback always goes here
__metaclass__ = ABCMeta
MAX_ROWS = 30000000
def __init__(self,name,years,spark=None,mysql=None):
MSoftware.__init__(self,name,spark,mysql)
self.years = years
...
TTime.py
from mouse.Mouse import Mouse
from mouse.MySQLMSoftware import MySQLMSoftware
class TTime(MySQLMSoftware) :
DATABASE = "Database"
NAME = "table"
YEARS = [2014,2016]
def __init__(self,spark=None,mysql=None):
MySQLMSoftware.__init__(self,TTime.NAME,TTime.YEARS,spark,mysql)
...
main.py
import sys
from mouse.Mouse import Mouse
from mouse.TTime import TTime
...
MSoftwarehas a metaclass (which isn'tABCMeta) -- Is that true? If so, you might be able to try__metaclass__ = type('MySQLMSoftware', (type(MSoftware), ABCMeta), {}). I don't have any of these classes to play around with, so I can't guarantee that it'll work...objectthis is the first time I've ever seen the__metaclass__declaration. I'll give your suggestion a shot.__metaclass__syntax changes with python3.x and there would be no error just setting a__metaclass__attribute on a class in python3.x.MSoftwareclass in anMSoftware.pyfile, but your other file (where the exception is happening) is inheriting from anMSoftwareclass defined in amousemodule, not anMSoftwaremodule. Can you find and showmouse.py? Perhapsmouse.MSoftwareis not the same asMSoftware.MSoftware.