import collections
def MetaNode(values):
class Meta(type):
def __new__(cls, name, bases, extra):
class AbstractNode(collections.namedtuple(name, values)):
def __new__(cls, *args, children=None, **kwargs):
return super().__new__(cls, *args, **kwargs)
def __init__(self, *args, children=None, **kwargs):
super().__init__()
self.children = children or []
return super().__new__(cls, name, bases + (AbstractNode,), extra)
return Meta
class RootNode(metaclass=MetaNode("a b c")):
pass
root = RootNode(1, 2, c=3)
print(root, root.children)
root = RootNode(1, 2, c=3, children=["yoba"])
print(root, root.children)
aW1wb3J0IGNvbGxlY3Rpb25zCgoKZGVmIE1ldGFOb2RlKHZhbHVlcyk6CgogICAgY2xhc3MgTWV0YSh0eXBlKToKCiAgICAgICAgZGVmIF9fbmV3X18oY2xzLCBuYW1lLCBiYXNlcywgZXh0cmEpOgoKICAgICAgICAgICAgY2xhc3MgQWJzdHJhY3ROb2RlKGNvbGxlY3Rpb25zLm5hbWVkdHVwbGUobmFtZSwgdmFsdWVzKSk6CgogICAgICAgICAgICAgICAgZGVmIF9fbmV3X18oY2xzLCAqYXJncywgY2hpbGRyZW49Tm9uZSwgKiprd2FyZ3MpOgoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gc3VwZXIoKS5fX25ld19fKGNscywgKmFyZ3MsICoqa3dhcmdzKQoKICAgICAgICAgICAgICAgIGRlZiBfX2luaXRfXyhzZWxmLCAqYXJncywgY2hpbGRyZW49Tm9uZSwgKiprd2FyZ3MpOgoKICAgICAgICAgICAgICAgICAgICBzdXBlcigpLl9faW5pdF9fKCkKICAgICAgICAgICAgICAgICAgICBzZWxmLmNoaWxkcmVuID0gY2hpbGRyZW4gb3IgW10KCiAgICAgICAgICAgIHJldHVybiBzdXBlcigpLl9fbmV3X18oY2xzLCBuYW1lLCBiYXNlcyArIChBYnN0cmFjdE5vZGUsKSwgZXh0cmEpCgogICAgcmV0dXJuIE1ldGEKCgpjbGFzcyBSb290Tm9kZShtZXRhY2xhc3M9TWV0YU5vZGUoImEgYiBjIikpOgoKICAgIHBhc3MKICAgIAogICAgCnJvb3QgPSBSb290Tm9kZSgxLCAyLCBjPTMpCnByaW50KHJvb3QsIHJvb3QuY2hpbGRyZW4pCgpyb290ID0gUm9vdE5vZGUoMSwgMiwgYz0zLCBjaGlsZHJlbj1bInlvYmEiXSkKcHJpbnQocm9vdCwgcm9vdC5jaGlsZHJlbik=