pythran/conversion.py
def to_ast(value):
    """
    Turn a value into ast expression.

    >>> a = 1
    >>> print(ast.dump(to_ast(a)))
    Num(n=1)
    >>> a = [1, 2, 3]
    >>> print(ast.dump(to_ast(a)))
    List(elts=[Num(n=1), Num(n=2), Num(n=3)], ctx=Load())
    """

    if any(value is t for t in (bool, int, float)):
        iinfo = np.iinfo(int)
        if isinstance(value, int) and not (iinfo.min <= value <= iinfo.max):
            from pythran.syntax import PythranSyntaxError
            raise PythranSyntaxError("constant folding results in big int")
        return builtin_folding(value)
    elif isinstance(value, np.generic):
        return to_ast(value.item())
    elif isinstance(value, (numbers.Number, str, bool, type(None))):
        return ast.Constant(value, None)
    elif isinstance(value, (list, tuple, set, dict, np.ndarray)):
        return size_container_folding(value)
    elif hasattr(value, "__module__") and value.__module__ == "builtins":
        # TODO Can be done the same way for others modules
        return builtin_folding(value)
    # only meaningful for python3
    elif isinstance(value, (filter, map, zip)):
        return to_ast(list(value))
    elif isinstance(value, np._globals._NoValueType):
        return ast.Attribute(ast.Attribute(ast.Name('numpy', ast.Load(), None,
                                                    None), '_globals',
                                           ast.Load()),
                             '_NoValueType', ast.Load())
    raise ToNotEval()

    Turn a value into ast expression.

    >>> a = 1
    >>> print(ast.dump(to_ast(a)))
    Num(n=1)
    >>> a = [1, 2, 3]
    >>> print(ast.dump(to_ast(a)))
    List(elts=[Num(n=1), Num(n=2), Num(n=3)], ctx=Load())
    
Turn a value into ast expression.
Turn a value into ast expression .
def to_ast(value):
    if any(value is t for t in (bool, int, float)):
        iinfo = np.iinfo(int)
        if isinstance(value, int) and not (iinfo.min <= value <= iinfo.max):
            from pythran.syntax import PythranSyntaxError
            raise PythranSyntaxError("constant folding results in big int")
        return builtin_folding(value)
    elif isinstance(value, np.generic):
        return to_ast(value.item())
    elif isinstance(value, (numbers.Number, str, bool, type(None))):
        return ast.Constant(value, None)
    elif isinstance(value, (list, tuple, set, dict, np.ndarray)):
        return size_container_folding(value)
    elif hasattr(value, "__module__") and value.__module__ == "builtins":
        return builtin_folding(value)
    elif isinstance(value, (filter, map, zip)):
        return to_ast(list(value))
    elif isinstance(value, np._globals._NoValueType):
        return ast.Attribute(ast.Attribute(ast.Name('numpy', ast.Load(), None,
                                                    None), '_globals',
                                           ast.Load()),
                             '_NoValueType', ast.Load())
    raise ToNotEval()
def to_ast ( value ) : if any ( value is t for t in ( bool , int , float ) ) : iinfo = np . iinfo ( int ) if isinstance ( value , int ) and not ( iinfo . min <= value <= iinfo . max ) : from pythran . syntax import PythranSyntaxError raise PythranSyntaxError ( "constant folding results in big int" ) return builtin_folding ( value ) elif isinstance ( value , np . generic ) : return to_ast ( value . item ( ) ) elif isinstance ( value , ( numbers . Number , str , bool , type ( None ) ) ) : return ast . Constant ( value , None ) elif isinstance ( value , ( list , tuple , set , dict , np . ndarray ) ) : return size_container_folding ( value ) elif hasattr ( value , "__module__" ) and value . __module__ == "builtins" : return builtin_folding ( value ) elif isinstance ( value , ( filter , map , zip ) ) : return to_ast ( list ( value ) ) elif isinstance ( value , np . _globals . _NoValueType ) : return ast . Attribute ( ast . Attribute ( ast . Name ( 'numpy' , ast . Load ( ) , None , None ) , '_globals' , ast . Load ( ) ) , '_NoValueType' , ast . Load ( ) ) raise ToNotEval ( )
Turn a value into ast expression.
Turn a value into ast expression .
"""
    Turn a value into ast expression.

    >>> a = 1
    >>> print(ast.dump(to_ast(a)))
    Num(n=1)
    >>> a = [1, 2, 3]
    >>> print(ast.dump(to_ast(a)))
    List(elts=[Num(n=1), Num(n=2), Num(n=3)], ctx=Load())
    """ # TODO Can be done the same way for others modules # only meaningful for python3
value