为什么在这种情况下,无需在python中使用“ metaclass”关键字

时间:2019-11-18 06:48:11

标签: python metaclass

        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有什么区别?

0 个答案:

没有答案