title: Is there a way to type a recursive dataclass?
body: <p>Suppose you have the following dataclass</p>
  
  <pre><code>@dataclass
  class Task:
      subTasks: Optional[List[Task]]
  </code></pre>
  
  <p>This is not possible, since <code>Task</code> is not declared yet.</p>
  
  <p>I am using Python 3.6 w/ <code>dacite</code> + <code>dataclasses</code> to parse a large dictionary into a dataclass.</p>
  
  <p>Currently I've been doing it like this:</p>
  
  <pre><code>from dataclasses import dataclass
  from dacite import from_dict
  
  @dataclass
  class Task:
      subTasks: Optional[List]
  
      def process_sub_tasks(self) -&gt; 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()
  </code></pre>
  
  <p>I was wondering if there's a way to type <code>subTasks</code> somehow to make it know that it is also a <code>List[Task]</code> object, rather than a generic <code>List</code></p>