I don't know what does super().__init__(*args, **kwargs)
do here.
class B(type):
def __init__(self, *args, **kwargs):
self.a = 'a'
super().__init__(*args, **kwargs)
class A(metaclass=B):
pass
As i know that super() returns an instance of a super class that tracks the current position in the MRO. When calling a method on a super instance, super looks up the next class in the MRO and calls the method on that class.
B.__mro__
(<class '__main__.B'>, <class 'type'>, <class 'object'>)
The super().__init__(*args, **kwargs)
call <class 'type'>'s __init__
method,what does it mean?
If i delete it
class B(type):
def __init__(self, *args, **kwargs):
self.a = 'a'
class A(metaclass=B):
pass
Initialize A
class
x=A()
x.a
'a'
The instance x
belong to A
class still own the attribution a
, it take same effect .