How do we include instances of a given class in its constructor?
class Node:
# Results in "Unresolved reference 'Node'"
def __init__(self, val: int, left: Node, right: Node):
self.val = val
self.left = left
self.right = right
Note: I have seen several questions similar to this but they are not asking exactly the same thing and/or are garbled.
Update Not surprisingly there does exist an answer somewhere in SOF to the question. But given the question I posed it's basically impossible to find that Q&A from This question already has answers here . The answer given in a comment below is
from __future_ import annotations
as the first line in the script/module