Python marshmallow tree structure with polymorphism
问题 I have the following code for a tree structure: class Node: def __init__(self, node_id: str): self.node_id = node_id self.children = [] def add_child(self, node: 'Node'): if isinstance(node, Node): self.children.append(node) class ValueNode(Node): def __init__(self, value: bool, **kwargs): Node.__init__(self, **kwargs) self.value = value class LogicNode(Node): def __init__(self, logic_operator: str, **kwargs): Node.__init__(self, **kwargs) self.logic_operator = logic_operator a = Node("a") b