Python有一个名为的单例NotImplemented
.
为什么有人想要返回NotImplemented
而不是提出NotImplementedError
异常?难道不会让它更难找到bug,例如执行无效方法的代码吗?
基于这个问题:Force child class to overrideparent'smethods,我的需要是在类中设置一个必须由子类覆盖的属性:
class Parent(ABC):
property = None # this one must be defined
# this should fail
class Child(Parent):
pass
Run Code Online (Sandbox Code Playgroud)
谢谢!