I am trying to define a python function annotation for the method of a class. The method returns a list whose elements are objects of the class. How can I do this?
Example,
class Node:
def __init__(self):
self.children = []
def get_children(self) -> list[Node]:
return self.children
Error message:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18676/2160074272.py in <module>
----> 1 class Node:
2 def __init__(self):
3 self.children = []
4
5 def get_children(self) -> list[Node]:
~\AppData\Local\Temp/ipykernel_18676/2160074272.py in Node()
3 self.children = []
4
----> 5 def get_children(self) -> list[Node]:
6 return self.children
NameError: name 'Node' is not defined