From 941c381f0201e99197e0e14fcf304b6107fb6739 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 13 Apr 2014 21:07:04 -0700 Subject: Add a wraps helper To smooth over the functools wraps difference in python2.x and python3.x add a helper that adds on the __wrapped__ attribute for python2.x (and does nothing in python3.2+). Resolves issue #65 --- six.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/six.py b/six.py index 6bc97c4..f6f680b 100644 --- a/six.py +++ b/six.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import functools import operator import sys import types @@ -631,6 +632,15 @@ if print_ is None: _add_doc(reraise, """Reraise an exception.""") +if sys.version_info[0:2] < (3, 2): + def wraps(fn): + def wrapper(f): + f = functools.wraps(fn)(f) + f.__wrapped__ = getattr(fn, '__wrapped__', fn) + return f + return wrapper +else: + wraps = functools.wraps def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" -- cgit v1.2.1