Python metaclass conflict/Type error -


i'm debugging python script (python isn't go language), , first time i'm working metaclass's in python. i'm getting metaclass conflict error when run code below.

typeerror: error when calling metaclass bases     metaclass conflict: metaclass of derived class must (non-strict) subclass of metaclasses of bases 

in attempting solve commented out metaclass declaration in mysqlmsoftware, thinking it's redundant inherits class same metaclass declaration, leads to:

typeerror: error when calling metaclass bases     module.__init__() takes @ 2 arguments (3 given) 

any insight, guidance or direction appreciated. i've been reading python's metaclass implementation , issue isn't popping out 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 abc import abcmeta, abstractmethod  class mysqlmsoftware(msoftware): # traceback 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 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 mouse.mouse import mouse mouse.ttime import ttime  ... 

the issue has imports, , confusion between identically named classes , modules. msoftware you're importing in mysqlmsoftware.py module implemented in msoftware.py, not class of same name within module. latter (without changing imports), you'd need use msoftware.msoftware. there may similar issue mouse class , module (which worse, since top level package named mouse too).

try changing line:

from mouse import mouse, msoftware 

to these 2 lines:

from mouse.mouse import mouse mouse.msoftware import msoftware 

this fix metaclass conflict issue, , make metaclass declaration in mysqlmsoftware class unnecessary.

i'd note root cause of issue (from higher level perspective) poor module design. have several modules each appear contain single class same name them. that's common project layout in other languages (like java), it's not necessary or desirable in python. there's never reason mouse.mouse.mouse thing.

probably should combine (or maybe all) of package's modules smaller number of files, starting putting of stuff in mouse/__init__.py (or top level mouse.py if combine them , don't need package more). way won't have quite many redundant imports.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -