Resolving metaclass conflicts

后端 未结 6 1231
时光取名叫无心
时光取名叫无心 2020-12-03 09:25

I need to create a class that uses a different base class depending on some condition. With some classes I get the infamous:

TypeError: metaclass conflict: t         


        
6条回答
  •  春和景丽
    2020-12-03 10:09

    To use the pattern described by @michael, but with both Python 2 and 3 compatibility (using the six library):

    from six import with_metaclass
    
    class M_C(M_A, M_B):
        pass
    
    class C(with_metaclass(M_C, A, B)):
        # implement your class here
    

提交回复
热议问题