'Set the environment for all nodes.'

def set_environment(self, environment):

    todo = deque([self])
    while todo:
        node = todo.popleft()
        node.environment = environment
        todo.extend(node.iter_child_nodes())
    return self
