Created
April 2, 2012 09:43
-
-
Save Arachnid/2282182 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _make_skel_func(code, num_closures): | |
""" Creates a skeleton function object that contains just the provided | |
code and the correct number of cells in func_closure. All other | |
func attributes (e.g. func_globals) are empty. | |
""" | |
#build closure (cells): | |
cellnew = ctypes.pythonapi.PyCell_New | |
cellnew.restype = ctypes.py_object | |
cellnew.argtypes = (ctypes.py_object,) | |
dummy_closure = tuple(map(lambda i: cellnew(None), range(num_closures))) | |
return types.FunctionType(code, {'__builtins__': __builtins__}, | |
None, None, dummy_closure) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment