Note that sometimes you will want to use the class type name inside its own definition, for example when using Python Typing module, e.g.
class Tree:
def __init__(self, left: Tree, right: Tree):
self.left = left
self.right = right
This will also result in
NameError: name 'Tree' is not defined
That's because the class has not been defined yet at this point. The workaround is using so called Forward Reference, i.e. wrapping a class name in a string, i.e.
class Tree:
def __init__(self, left: 'Tree', right: 'Tree'):
self.left = left
self.right = right