import ast


def function_node(code):
    """Return AST node for first function in code string.

    :param str code: Code, e.g. 'def add(a,b): return a+b'
    :return: AST node for function in code.
    :rtype: ast object
    """
    module = ast.parse(code)
    for node in ast.walk(module):
        if isinstance(node, ast.FunctionDef):
            return node
    raise ValueError("Code has no function: " + code)