First of all—thank you for the feedback! Support for classes is in its early days and reports from intrepid users are super valuable.
To summarize, it seems that you are running into two problems:


torch.jit.annotate() is not doing implicit type promotion from T to Optional[T] for class types.
This is a bug on our side, and we’ll look into fixing it. Can you file a Github task and we can track it there?


Augmented assignment doesn’t work on non-tensors. This is a known issue, and we have a fix coming this week for it. In the meantime, just re-assigning is an easy workaround:


def add_child(self):
    self.num_children = self.num_children + 1