Oct-06-2022, 08:31 PM
Use type annotations. This example is tricky since Node has not been defined. The convention for this case is to use a string.
class Node: def __init__(self, value:float, prev:'Node' = None, next:'Node' = None): self.value = value self.prev = prev self.next = nextYou can also use typing_extensions.Self
from typing_extensions import Self class Node: def __init__(self, value:float, prev:Self = None, next:Self = None): self.value = value self.prev = prev self.next = next