rope.base.evaluate

Attributes

BadIdentifierError

Classes

ScopeNameFinder

StatementEvaluator

A node visitor base class that walks the abstract syntax tree and calls a

Functions

eval_location(pymodule, offset)

Find the pyname at the offset

eval_location2(pymodule, offset)

Find the primary and pyname at offset

eval_node(scope, node)

Evaluate a ast.AST node and return a PyName

eval_node2(scope, node)

eval_str(holding_scope, name)

eval_str2(holding_scope, name)

Module Contents

rope.base.evaluate.BadIdentifierError
rope.base.evaluate.eval_location(pymodule, offset)

Find the pyname at the offset

rope.base.evaluate.eval_location2(pymodule, offset)

Find the primary and pyname at offset

rope.base.evaluate.eval_node(scope, node)

Evaluate a ast.AST node and return a PyName

Return None if the expression cannot be evaluated.

rope.base.evaluate.eval_node2(scope, node)
rope.base.evaluate.eval_str(holding_scope, name)
rope.base.evaluate.eval_str2(holding_scope, name)
class rope.base.evaluate.ScopeNameFinder(pymodule)
module_scope
lines
worder
get_pyname_at(offset)
get_primary_and_pyname_at(offset: int) → Tuple[rope.base.pynames.PyName | None, rope.base.pynames.PyName | None]
get_enclosing_function(offset)
class rope.base.evaluate.StatementEvaluator(scope)

Bases: rope.base.ast.RopeNodeVisitor

A node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the visit method.

This class is meant to be subclassed, with the subclass adding visitor methods.

Per default the visitor functions for the nodes are 'visit_' + class name of the node. So a TryFinally node visit function would be visit_TryFinally. This behavior can be changed by overriding the visit method. If no visitor function exists for a node (return value None) the generic_visit visitor is used instead.

Don’t use the NodeVisitor if you want to apply changes to nodes during traversing. For this a special visitor exists (NodeTransformer) that allows modifications.

scope
result = None
old_result = None
visit(node)

Modified from ast.NodeVisitor to match rope’s existing Visitor implementation