pyrser/parsing/node.py
def normalize(ast: Node) -> Node:
    """
    Normalize an AST nodes.

    all builtins containers are replace by referencable subclasses
    """
    res = ast
    typemap = {DictNode, ListNode, TupleNode}
    if type(ast) is dict:
        res = DictNode(ast)
    elif type(ast) is list:
        res = ListNode(ast)
    elif type(ast) is tuple:
        res = TupleNode(ast)
    # in-depth change
    if hasattr(res, 'items'):
        for k, v in res.items():
            res[k] = normalize(v)
    elif hasattr(res, '__getitem__'):
        for idx, v in zip(range(len(res)), res):
            res[idx] = normalize(v)
    if type(res) not in typemap and hasattr(res, '__dict__'):
        subattr = vars(res)
        for k, v in subattr.items():
            setattr(res, k, normalize(v))
    return res
def normalize(ast: Node) -> Node:
    res = ast
    typemap = {DictNode, ListNode, TupleNode}
    if type(ast) is dict:
        res = DictNode(ast)
    elif type(ast) is list:
        res = ListNode(ast)
    elif type(ast) is tuple:
        res = TupleNode(ast)
    # in-depth change
    if hasattr(res, 'items'):
        for k, v in res.items():
            res[k] = normalize(v)
    elif hasattr(res, '__getitem__'):
        for idx, v in zip(range(len(res)), res):
            res[idx] = normalize(v)
    if type(res) not in typemap and hasattr(res, '__dict__'):
        subattr = vars(res)
        for k, v in subattr.items():
            setattr(res, k, normalize(v))
    return res
def normalize ( ast : Node ) -> Node : res = ast typemap = { DictNode , ListNode , TupleNode } if type ( ast ) is dict : res = DictNode ( ast ) elif type ( ast ) is list : res = ListNode ( ast ) elif type ( ast ) is tuple : res = TupleNode ( ast ) # in-depth change if hasattr ( res , 'items' ) : for k , v in res . items ( ) : res [ k ] = normalize ( v ) elif hasattr ( res , '__getitem__' ) : for idx , v in zip ( range ( len ( res ) ) , res ) : res [ idx ] = normalize ( v ) if type ( res ) not in typemap and hasattr ( res , '__dict__' ) : subattr = vars ( res ) for k , v in subattr . items ( ) : setattr ( res , k , normalize ( v ) ) return res
Normalize an AST nodes.

    all builtins containers are replace by referencable subclasses
Normalize an AST nodes .