【发布时间】:2020-03-18 00:59:26
【问题描述】:
有没有办法输入一个抽象的父类方法,使得子类方法知道返回自己,而不是抽象父类。
class Parent(ABC):
@abstractmethod
def method(self) -> [what to hint here]:
pass
class Child1(Parent)
def method(self):
pass
def other_method(self):
pass
class GrandChild1(Child1)
def other_method_2(self):
pass
这更多是为了改进 PyCharm 或 VScode 的 python 插件等 IDE 的自动完成功能。
【问题讨论】:
-
@MadPhysicist 与此处无关,abstractmethods 需要使用
pass或... -
@juanpa.arrivillaga。哇。当我读到通行证时,我忘记了那部分。我想这周该睡觉了。
标签: python abstract-class type-hinting abc