简体   繁体   English

ABCMeta 没有给我一个例外

[英]ABCMeta doesn't give me an exception

ABCMeta assures that the constructor gives an exception if you try to instantiate the abstract class, then why doesn't it give me an exception in the console if I run this code? ABCMeta 确保如果您尝试实例化抽象 class,构造函数会给出异常,那么如果我运行此代码,为什么它不在控制台中给我一个异常?

from abc import ABCMeta

class MyClass(metaclass=ABCMeta):
    pass

x = MyClass()

From the docs ( https://docs.python.org/3/library/abc.html#abc.ABCMeta ):从文档( https://docs.python.org/3/library/abc.html#abc.ABCMeta ):

A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods and properties are overridden除非重写其所有抽象方法和属性,否则无法实例化具有从 ABCMeta 派生的元类的 class

As you have no abstract methods or properties in MyClass , it can be instantiated.由于MyClass中没有抽象方法或属性,因此可以对其进行实例化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM