Skip to content
Snippets Groups Projects
Commit c79bb96d authored by Donald Stufft's avatar Donald Stufft
Browse files

Conditionally use functools.wraps if there is a __name__

This is a work around to https://bugs.pypy.org/issue1452
parent be4fa256
No related branches found
No related tags found
No related merge requests found
...@@ -77,12 +77,23 @@ ffi.cdef( ...@@ -77,12 +77,23 @@ ffi.cdef(
lib = ffi.verify("#include <sodium.h>", libraries=["sodium"]) 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 # 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 # 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 # negative integers are truthy. This wrapper has them return True/False as
# you'd expect in Python # you'd expect in Python
def wrap_nacl_function(func): def wrap_nacl_function(func):
@functools.wraps(func) @wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
ret = func(*args, **kwargs) ret = func(*args, **kwargs)
return ret == 0 return ret == 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment