Skip to main content
Version: 1.4.0 (latest)

common.reflection.utils

get_literal_defaults

def get_literal_defaults(
node: Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> Dict[str, str]

[view_source]

Extract defaults from function definition node literally, as pieces of source code

get_func_def_node

def get_func_def_node(
f: AnyFun) -> Union[ast.FunctionDef, ast.AsyncFunctionDef]

[view_source]

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]

[view_source]

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

[view_source]

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

[view_source]

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]

[view_source]

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

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.