2

I have the Node class and the Node class has 2 children, child A and B, but they are the same class with the same structure, because the child could have its own child.

The code is in python, and the language don't let my do the next, mark me an error:

class Node:
    a: Node
    b: Node
    name: str
    value: int

Is there a way to do that, the Object itself nested?

My regards

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

3

According to How do I specify that the return type of a method is the same as the class itself?, the simplest solution is to use a string with the class name:

a : 'Node'
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268