How to construct a callable from a Python code object?
Question: _Realize this is a rather obscure question, so I'll explain why I'm looking
into this._

A Python jit compiler takes a callable and returns a callable.

This is fine, however - the API I'm currently working with uses a Python code
object.

A simplistic answer to this question would be to write a function to execute
the code, eg:

    
    
    def code_to_function(code):
        def fn():
            return eval(code)
        return fn
    
    # example use
    code  = compile("1 + 1", '<string>', 'eval')
    fn = code_to_function(code)
    print(fn())  # --> 2
    

Which is correct, but in this case the jit (happens to be numba), won't
evaluate the actual number crunching parts - which is needed to be useful.

So the question is, how to take a code object which evaluates to a value, and
convert/construct a callable from it?

* * *

Update, thanks to @jsbueno's answer, [here's an example of a simple expression
evaluator using
numba](https://gist.github.com/ideasman42/c9ef91230ac67de6572f).


Answer: 
    from types import FunctionType
    
    new_function = FunctionType(code,  globals[, name[, argdefs[, closure]]])
    

The remaining parameters above may be taken from the original function you
have.

