From c79bb96d5f86edb6554d945f17c46e527b336259 Mon Sep 17 00:00:00 2001 From: Donald Stufft <donald@stufft.io> Date: Sun, 14 Apr 2013 01:07:42 -0400 Subject: [PATCH] Conditionally use functools.wraps if there is a __name__ This is a work around to https://bugs.pypy.org/issue1452 --- nacl/nacl.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nacl/nacl.py b/nacl/nacl.py index 20cc74d3..8fb06b25 100644 --- a/nacl/nacl.py +++ b/nacl/nacl.py @@ -77,12 +77,23 @@ ffi.cdef( lib = ffi.verify("#include <sodium.h>", libraries=["sodium"]) +# This works around a bug in PyPy where CFFI exposed functions do not have a +# __name__ attribute. See https://bugs.pypy.org/issue1452 +def wraps(wrapped): + def inner(func): + if hasattr(wrapped, "__name__"): + return functools.wraps(wrapped)(func) + else: + return func + return inner + + # A lot of the functions in nacl return 0 for success and a negative integer # for failure. This is inconvenient in Python as 0 is a falsey value while # negative integers are truthy. This wrapper has them return True/False as # you'd expect in Python def wrap_nacl_function(func): - @functools.wraps(func) + @wraps(func) def wrapper(*args, **kwargs): ret = func(*args, **kwargs) return ret == 0 -- GitLab