I want to define a Node for a Linked List, using type hints. An instance of Node needs a reference to another instance of Node, so I want to accept an optional parameter of type Node
in my __init__
.
I tried this:
from typing import Optional
class Node:
def __init__(self, value: int, next: Optional[Node] = None):
pass
I get an error: Node is not defined
from Optional[Node]
.