template <class U, class V, bool Exists = !!sizeof(std::declval<T>() == std::declval<Arg>())>
static std::true_type Func(const T&, const Arg&);
在MetaNormal2中,我不使用关键字“ metaclass =”,但是它的元类是Meta,为什么类MetaNormal2不需要对特定的元类使用“ metaclass”?
确实,如果我使用class Meta(type): # ➋
def __new__(cls, name, bases, d):
print("call Meta __new__")
d["a"] = "a"
return super(Meta, cls).__new__(cls, name, bases, d)
def __init__(self, *args, **kwargs):
print("call Meta __init__")
super(Meta, self).__init__(*args, **kwargs)
meta_definition = Meta('meta', (), {})
class MetaNormal1(metaclass = Meta):
pass
class MetaNormal2(meta_definition):
pass
print(type(MetaNormal2))
>>> <class '__main__.Meta'>
会出错:metaclass=meta_definition
MetaNormal1和MetaNormal2有什么区别?