def get_sub_template(template, path):
    sub = template
    for el in path:
        # TODO: optimize it
        if el == 0:
            try:
                sub = sub[0]
            except IndexError:
                return lambda node, _: False
        elif el == 1:
            sub = sub[1:]
        elif isinstance(sub, ast.AST) and sub._fields in el:
            sub = getattr(sub, el)
        elif callable(sub):
            return lambda node, _: True
        else:
            raise Exception('Unknown path', path, 'in', astor.dump(sub))
    return sub
dataset/ETHPy150Open Suor/flaws/flaws/patterns.py/get_sub_template/swapped operands of `in`