def get_arg_from_definition(root, atok): if not match_node(root, ast.arg): if match_node(root, ast.FunctionDef): fix_definition(root, atok) return None if match_parent(root, ast.FunctionDef): fix_definition(root.parent, atok) elif match_parent(root.parent, ast.FunctionDef): fix_definition(root.parent.parent, atok) else: return None return root
def get_boolean_right(root): if not match_node(root, ast.BoolOp) or match_parent(root, ast.BoolOp): return None items = root.values if len(items) >= 2: return items[-1] return None
def get_boolean_middle(root): if not match_node(root, ast.BoolOp) or match_parent(root, ast.BoolOp): return None items = root.values if len(items) == 3: return items[1] return None
def get_arithmetic_middle(root): if not match_node(root, ast.BinOp) or match_parent(root, ast.BinOp): return None items = get_sub_index(root, None) if len(items) == 3: return items[1] return None
def get_arithmetic_right(root): if not match_node(root, ast.BinOp) or match_parent(root, ast.BinOp): return None items = get_sub_index(root, None) if len(items) >= 2: return items[-1] return None
def single(root): return match_parent(node,(),ast.Attribute)
def get_elif_condition(root): return ( root.test if match_node(root,(ast.If)) and match_parent(root,(ast.If)) and root.parent_field == "orelse" else None )
def get_pure_if_condition(root): return ( root.test if match_node(root,(ast.If)) and not (match_parent(root,(ast.If)) and root.parent_field == "orelse") else None )
def get_boolean(root): if not match_node(root, ast.BoolOp) or match_parent(root, ast.BoolOp): return None return root
def get_arithmetic(root): if not match_node(root, ast.BinOp) or match_parent(root, ast.BinOp): return None return root
def is_base(root): return ((getattr(root, "parent_field", "") == "bases" and match_parent(root, ast.ClassDef)) or (match_parent(root, ast.keyword) and match_parent(root.parent, ast.ClassDef)))