覆盖方法但保留装饰器(python)

Tom*_*Tom 1 python methods overwrite prefect

我有一个类和一个子类,并且想从框架prefect.io继承一个带有装饰器@task的方法。

\n

代码示例:

\n

班级

\n
@task\ndef test1(self):\n     pass\n
Run Code Online (Sandbox Code Playgroud)\n

子类

\n
def test2(self):\n     print("succeed")\n
Run Code Online (Sandbox Code Playgroud)\n

但现在方法test2不再具有装饰器@task了。我可以\xc2\xb4t在子类中声明@task 。我是否可以覆盖该方法但保留@task

\n