common.reflection.utils
get_literal_defaults
def get_literal_defaults(node: ast.FunctionDef) -> Dict[str, str]
Extract defaults from function definition node literally, as pieces of source code
get_func_def_node
def get_func_def_node(f: AnyFun) -> ast.FunctionDef
Finds the function definition node for function f by parsing the source code of the f's module
find_outer_func_def
def find_outer_func_def(node: ast.AST) -> Optional[ast.FunctionDef]
Finds the outer function definition node in which the 'node' is contained. Returns None if 'node' is toplevel.
set_ast_parents
def set_ast_parents(tree: ast.AST) -> None
Walks AST tree and sets the parent
attr in each node to the node's parent. Toplevel nodes (parent is a tree
) have the parent
attr set to None.
creates_func_def_name_node
def creates_func_def_name_node(func_def: ast.FunctionDef,
source_lines: Sequence[str]) -> ast.Name
Recreate function name as a ast.Name with known source code location
rewrite_python_script
def rewrite_python_script(
source_script_lines: List[str],
transformed_nodes: List[Tuple[ast.AST, ast.AST]]) -> List[str]
Replaces all the nodes present in transformed_nodes
in the script_lines
. The transformed_nodes
is a tuple where the first element
is must be a node with full location information created out of script_lines