From c872cd793f92405c80f7139c2c52432867498bc6 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 26 Jan 2014 21:19:28 +0100 Subject: [PATCH] Fix compatibility with Pypy (does not support __closure__ attribute for functions). --- src/utils/python.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/python.py b/src/utils/python.py index 4b9008204..acd2cba7d 100644 --- a/src/utils/python.py +++ b/src/utils/python.py @@ -58,8 +58,13 @@ def universalImport(*names): def changeFunctionName(f, name, doc=None): if doc is None: doc = f.__doc__ + if hasattr(f, '__closure__'): + closure = f.__closure__ + else: + # Pypy + closure = f.func_closure newf = types.FunctionType(f.__code__, f.__globals__, name, - f.__defaults__, f.__closure__) + f.__defaults__, closure) newf.__doc__ = doc return newf