Attempts to infer an abstract syntax tree from the provided value.
    
    - Python ast.AST instances are passed through.
    - Strings are parsed. A SyntaxError is raised if invalid.
    - Functions are sent through cypy.fn_get_source to get a source
      string, then parsed. If the source can't be a found, an exception is 
      raised by fn_get_source.
      
    .. WARNING:: Functions defined on the iPython command line do not have 
                 their source saved. A bug has been filed: 
                 
                 http://github.com/ipython/ipython/issues/issue/120

def infer_ast(src):
    """Attempts to infer an abstract syntax tree from the provided value.
    
    - Python ast.AST instances are passed through.
    - Strings are parsed. A SyntaxError is raised if invalid.
    - Functions are sent through cypy.fn_get_source to get a source
      string, then parsed. If the source can't be a found, an exception is 
      raised by fn_get_source.
      
    .. WARNING:: Functions defined on the iPython command line do not have 
                 their source saved. A bug has been filed: 
                 
                 http://github.com/ipython/ipython/issues/issue/120
    """
    if isinstance(src, _ast.AST):
        return src
    elif isinstance(src, str):
        return _ast.parse(src)
    else:
        # if a function instance is passed in, it's source is found
        # and parsed. note that finding source can be precarious for
        # functions defined on the command line. If you get an error
        # you'll have to use strings instead of regular function
        # definitions
        src = cypy.fn_get_source(src)
        return _ast.parse(src)