Suppose you have the following dataclass
@dataclass
class Task:
    subTasks: Optional[List[Task]]
This is not possible, since Task is not declared yet.
I am using Python 3.6 w/ dacite + dataclasses to parse a large dictionary into a dataclass.
Currently I've been doing it like this:
from dataclasses import dataclass
from dacite import from_dict
@dataclass
class Task:
    subTasks: Optional[List]
    def process_sub_tasks(self) -> None:
        cls = type(self)
        if self.subTasks:
            self.subTasks = [from_dict(data_class=cls, data=d) for d in self.subTasks]
            for subtask in self.subTasks:
                subtask.process_sub_tasks()
I was wondering if there's a way to type subTasks somehow to make it know that it is also a List[Task] object, rather than a generic List
