code_utils.py#

Tools for working with code.

class openmdao.utils.code_utils.LambdaPickleWrapper(lambda_func)[source]

Bases: object

A wrapper for a lambda function that allows it to be pickled.

Parameters:
lambda_funcfunction

The lambda function to be wrapped.

Attributes:
_funcfunction

The lambda function.

_srcstr

The isolated source of the lambda function.

__init__(lambda_func)[source]

Initialize the wrapper.

Parameters:
lambda_funcfunction

The lambda function to be wrapped.

openmdao.utils.code_utils.get_class_attributes(fname, class_dict=None)[source]

Find all referenced attributes in all classes defined in the given file.

Parameters:
fnamestr

File name.

class_dictdict or None

Dict mapping class names to attribute names.

Returns:
dict

The dict maps class name to a set of attribute names.

openmdao.utils.code_utils.get_nested_calls(class_, method_name, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Display the call tree for the specified class method and all ‘self’ class methods it calls.

Parameters:
class_class

The starting class.

method_namestr

The name of the class method.

streamfile-like

The output stream where output will be displayed.

Returns:
networkx.DiGraph

A graph containing edges from methods to their sub-methods.

openmdao.utils.code_utils.is_lambda(f)[source]

Return True if the given function is a lambda function.

Parameters:
ffunction

The function to check.

Returns:
bool

True if the given function is a lambda function.