“任务”类实例需要包含有关其先决任务的信息。
import typing
class Task:
def __init__(
self,
prerequisite: typing.Set(Task)
):
self.prerequisite = prerequisite
File "test.py", line 3, in <module>
class Task:
File "test.py", line 6, in Task
prerequisite: typing.Set(Task)
NameError: name 'Task' is not defined
答案 0 :(得分:0)
您可以使用和抽象类
from abc import ABC
import typing
class TaskType(ABC):
pass
class Task:
def __init__(self, prerequisite: typing.Set(TaskType)):
self.prerequisite = prerequisite