API Reference for Enthought Tool Suite 3.2.0

AST Visitor Class for finding the return_vals from a function.

return_vals is a list of lists. Each list is the set of variable names from a return statement in the function. For example:

>>> code = '''
... def foo(x):
...     if x:
...         return vp, vs
...     else:
...         return vp
... '''
>>> import compiler
>>> ast = compiler.parse(code)
>>> walk(ast, ReturnVariablesFinder()).return_vals
[['vp', 'vs'], ['vp']]

This will only return the values from functions that have simple return statements. For example

>>> code = '''
... def foo(x):
...     return bar(x)
... '''
>>> import compiler
>>> ast = compiler.parse(code)
>>> walk(ast, ReturnVariablesFinder()).return_vals
[['result']]

fixme: Handle empty list return statement in some way.

Method summary

Methods

© Copyright 2002-2009 Enthought, Inc.