Mark Shannon <m...@hotpy.org> added the comment:
You need to define __builtins__ in the globals dictionary. def func(s): return len(s) text = "abc" print(func(text)) FuncType = type(func) func_globals = {"__builtins__":__builtins__.__dict__} code = func.__code__ func2 = FuncType(code, func_globals) print(func2(text)) works for both 3.9 and 3.10. Cloudpickle needs to initialize the globals dict *before* creating the function. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43228> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com