Metaclass multiple inheritance inconsistency

后端 未结 2 1930
[愿得一人]
[愿得一人] 2020-12-28 11:58

Why is this:

class MyType(type):
    def __init__(cls, name, bases, attrs):
        print \'created\', cls
class MyMixin:
    __metaclass__ = MyType
class My         


        
2条回答
  •  余生分开走
    2020-12-28 12:11

    Here, you are inheriting the parent class, and the parent class is already inheriting another class, so there is no need to inherit the class that the parent class already inherited.

    For example:

    class A(object):
    .
    .
    class B(object, A):
    .
    .
    

    It will throw an error because A is inheriting the class Object and B is inheriting the A, so indirectly B is inheriting object, so there is no need to inherit object. . . .

    The Solution is to just remove the object class from class B ... arguments list.

提交回复
热议问题