wickman / pystachio

type-checked dictionary templating library for python
MIT License
91 stars 22 forks source link

[Feature Request] Recursive Types #31

Closed tomtwttr closed 4 years ago

tomtwttr commented 5 years ago
Class Node(Struct)
 child=Node
wickman commented 5 years ago

python itself doesn't support recursive types, so even to express this you will need to create a function called something like Indirect, then do

class Tree(Struct):
  value = Integer
  node_left = Indirect('Tree')
  node_right = Indirect('Tree')

The Indirect function would then create something that could be interpreted by the metaclass to hand to the type system that redirects the type checker back to the Tree type.