如果我重写了一个抽象属性方法,但忘记指定它仍然是子类中的属性方法,我希望 Python 解释器对我大喊大叫。
class Parent(metaclass=ABCMeta):
@property
@abstractmethod
def name(self) -> str:
pass
class Child(Parent):
@property # If I forget this, I want Python to yell at me.
def name(self) -> str:
return 'The Name'
if __name__ == '__main__':
print(Child().name)
Python 真的没有内置方法可以做到这一点吗?我真的必须创建自己的装饰器来处理这种行为吗?
白衣非少年
郎朗坤
qq_笑_17
相关分类