I'm trying to implement Nodes and Edges for a graph. Here is my code:
from typing import NamedTuple, List
class Node(NamedTuple):
name: str
edges: List[Edge]
class Edge(NamedTuple):
src: Node
dest: Node
This raises an error because the Edge
type is not defined when Node
is created.
NameError: name 'Edge' is not defined
Switching the definitions around doesn't work because Edge
also refers to Node
.
How can I make it work?