How to annotate a class method parameter with the class it self [duplicate]

TreeNode is only defined after the class TreeNode body. Use from __future__ import annotations or child: 'TreeNode' to make a forward reference.

class TreeNode:
    def __init__(
        self,
        element: Entity,
        children=None
    ):
        if children is None:
            self.children = []
        else:
            self.children = children
        self.element = element

    def add_children(self, child: 'TreeNode'):
        self.children.append(child)