bag.util.parse

This module defines parsing utility methods.

Module Contents

Classes

ExprVarScanner

This node visitor collects all variable names found in the

Functions

get_variables(expr)

Parses the given Python expression and return a list of all variables.

class bag.util.parse.ExprVarScanner[source]

Bases: ast.NodeVisitor

This node visitor collects all variable names found in the AST, and excludes names of functions. Variables having dotted names are not supported.

visit_Name(node)[source]
visit_Call(node)[source]
visit_Attribute(node)[source]
bag.util.parse.get_variables(expr)[source]

Parses the given Python expression and return a list of all variables.

Parameters:

expr (str) – An expression string that we want to parse for variable names.

Returns:

var_list – Names of variables from the given expression.

Return type:

list[str]