4
class AbstractBaseClass:
  __metaclass__ = abc.ABCMeta

  @abc.abstractmethod
  def someMethod()

class DerviedClass(AbstractBaseClass):
  __metaclass__ = Singleton

  def someMethod():
    """dosomething"""
    pass

#defines singleton design pattern not defining for sake of simplicity 
class Singleton:

(see here Creating a singleton in Python)

I see following error

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

This seems to be becauase base class and derived class have two different metaclass defination. how do i go around this problem?

Community
  • 1
  • 1
konquestor
  • 1,308
  • 3
  • 15
  • 29
  • possible duplicate of [Triple inheritance causes metaclass conflict... Sometimes](http://stackoverflow.com/questions/6557407/triple-inheritance-causes-metaclass-conflict-sometimes) – Nagaraj Tantri Oct 08 '14 at 09:22
  • 1
    How to solve: Read - http://www.phyast.pitt.edu/~micheles/python/metatype.html – Nagaraj Tantri Oct 08 '14 at 09:23
  • Please refer http://stackoverflow.com/questions/33364070/python-implementing-singleton-as-metaclass-but-for-abstract-classes. – Ram Nov 05 '16 at 05:55

0 Answers0