Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def single(root):
	return match_parent(node,(),ast.Attribute)
Exemplo n.º 7
0
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		
	)
Exemplo n.º 8
0
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		
	)
Exemplo n.º 9
0
def get_boolean(root):
    if not match_node(root, ast.BoolOp) or match_parent(root, ast.BoolOp):
        return None
    return root
Exemplo n.º 10
0
def get_arithmetic(root):
    if not match_node(root, ast.BinOp) or match_parent(root, ast.BinOp):
        return None
    return root
Exemplo n.º 11
0
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)))