pymc4/ast_compiler.py
def recompile(source, filename, mode, flags=0, firstlineno=1, privateprefix=None):
    """Recompile output of uncompile back to a code object. source may also be preparsed AST."""
    if isinstance(source, ast.AST):
        a = source
    else:
        a = parse_snippet(source, filename, mode, flags, firstlineno)
    node = a.body[0]
    if not isinstance(node, ast.FunctionDef):
        raise ValueError("Expecting function AST node")

    c0 = compile(a, filename, mode, flags, True)

    # This code object defines the function. Find the function's actual body code:
    for c in c0.co_consts:
        if not isinstance(c, code):
            continue
        if c.co_name == node.name and c.co_firstlineno == node.lineno:
            break
    else:
        raise RuntimeError("Function body code not found")

    # Re-mangle private names:
    if privateprefix is not None:

        def fixnames(names):
            isprivate = re.compile("^__.*(?<!__)$").match
            return tuple(privateprefix + name if isprivate(name) else name for name in names)

        c = code(
            c.co_argcount,  # pylint: disable=undefined-loop-variable
            c.co_nlocals,  # pylint: disable=undefined-loop-variable
            c.co_stacksize,  # pylint: disable=undefined-loop-variable
            c.co_flags,  # pylint: disable=undefined-loop-variable
            c.co_code,  # pylint: disable=undefined-loop-variable
            c.co_consts,  # pylint: disable=undefined-loop-variable
            fixnames(c.co_names),  # pylint: disable=undefined-loop-variable
            fixnames(c.co_varnames),  # pylint: disable=undefined-loop-variable
            c.co_filename,  # pylint: disable=undefined-loop-variable
            c.co_name,  # pylint: disable=undefined-loop-variable
            c.co_firstlineno,  # pylint: disable=undefined-loop-variable
            c.co_lnotab,  # pylint: disable=undefined-loop-variable
            c.co_freevars,  # pylint: disable=undefined-loop-variable
            c.co_cellvars,  # pylint: disable=undefined-loop-variable
        )
    return c
Recompile output of uncompile back to a code object. source may also be preparsed AST.
Recompile output of uncompile back to a code object. source may also be preparsed AST.
Recompile output of uncompile back to a code object . source may also be preparsed AST .
def recompile(source, filename, mode, flags=0, firstlineno=1, privateprefix=None):
    if isinstance(source, ast.AST):
        a = source
    else:
        a = parse_snippet(source, filename, mode, flags, firstlineno)
    node = a.body[0]
    if not isinstance(node, ast.FunctionDef):
        raise ValueError("Expecting function AST node")
    c0 = compile(a, filename, mode, flags, True)
    for c in c0.co_consts:
        if not isinstance(c, code):
            continue
        if c.co_name == node.name and c.co_firstlineno == node.lineno:
            break
    else:
        raise RuntimeError("Function body code not found")
    if privateprefix is not None:
        def fixnames(names):
            isprivate = re.compile("^__.*(?<!__)$").match
            return tuple(privateprefix + name if isprivate(name) else name for name in names)
        c = code(
            c.co_argcount,  
            c.co_nlocals,  
            c.co_stacksize,  
            c.co_flags,  
            c.co_code,  
            c.co_consts,  
            fixnames(c.co_names),  
            fixnames(c.co_varnames),  
            c.co_filename,  
            c.co_name,  
            c.co_firstlineno,  
            c.co_lnotab,  
            c.co_freevars,  
            c.co_cellvars,  
        )
    return c
def recompile ( source , filename , mode , flags = 0 , firstlineno = 1 , privateprefix = None ) : if isinstance ( source , ast . AST ) : a = source else : a = parse_snippet ( source , filename , mode , flags , firstlineno ) node = a . body [ 0 ] if not isinstance ( node , ast . FunctionDef ) : raise ValueError ( "Expecting function AST node" ) c0 = compile ( a , filename , mode , flags , True ) for c in c0 . co_consts : if not isinstance ( c , code ) : continue if c . co_name == node . name and c . co_firstlineno == node . lineno : break else : raise RuntimeError ( "Function body code not found" ) if privateprefix is not None : def fixnames ( names ) : isprivate = re . compile ( "^__.*(?<!__)$" ) . match return tuple ( privateprefix + name if isprivate ( name ) else name for name in names ) c = code ( c . co_argcount , c . co_nlocals , c . co_stacksize , c . co_flags , c . co_code , c . co_consts , fixnames ( c . co_names ) , fixnames ( c . co_varnames ) , c . co_filename , c . co_name , c . co_firstlineno , c . co_lnotab , c . co_freevars , c . co_cellvars , ) return c
Recompile output of uncompile back to a code object.
Recompile output of uncompile back to a code object .
"""Recompile output of uncompile back to a code object. source may also be preparsed AST.""" # This code object defines the function. Find the function's actual body code: # Re-mangle private names: # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable # pylint: disable=undefined-loop-variable
source
filename
mode
flags
firstlineno
privateprefix