Fix compatibility with Pypy (does not support __closure__ attribute for functions).

This commit is contained in:
Valentin Lorentz 2014-01-26 21:19:28 +01:00
parent a7f750d273
commit c872cd793f

View File

@ -58,8 +58,13 @@ def universalImport(*names):
def changeFunctionName(f, name, doc=None): def changeFunctionName(f, name, doc=None):
if doc is None: if doc is None:
doc = f.__doc__ doc = f.__doc__
if hasattr(f, '__closure__'):
closure = f.__closure__
else:
# Pypy
closure = f.func_closure
newf = types.FunctionType(f.__code__, f.__globals__, name, newf = types.FunctionType(f.__code__, f.__globals__, name,
f.__defaults__, f.__closure__) f.__defaults__, closure)
newf.__doc__ = doc newf.__doc__ = doc
return newf return newf