Is there a way to define a parameter's type in a class such that the type references itself?
For example, the following won't run:
from typing import List
class Node:
def __init__(self, val: int=0, neighbors: List[Node]=[]):
self.val = val
self.neighbors = neighbors
Error:
Traceback (most recent call last):
File "node.py", line 3, in <module>
class Node:
File "node.py", line 4, in Node
def __init__(self, val: int=0, neighbors: List[Node]=[]):
NameError: name 'Node' is not defined