diff --git a/NEWS.rst b/NEWS.rst index f83af61..dbb3c98 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -5,6 +5,7 @@ Release History 0.3 (2012-01-XX) ~~~~~~~~~~~~~~~~ +* Wrapped callbacks now use functools.wraps to aid in introspection * Moved version number to a VERSION.txt file (read by both docs and setup.py) * Added NEWS.rst (and incorporated into documentation) diff --git a/contextlib2.py b/contextlib2.py index f02a381..65dd434 100644 --- a/contextlib2.py +++ b/contextlib2.py @@ -170,6 +170,7 @@ class ContextStack(object): Cannot suppress exceptions. """ + @wraps(callback) def _wrapper(exc_type, exc, tb): callback(*args, **kwds) return self.register_exit(_wrapper) diff --git a/test_contextlib2.py b/test_contextlib2.py index eb96cf1..7a3150b 100755 --- a/test_contextlib2.py +++ b/test_contextlib2.py @@ -317,6 +317,7 @@ class TestContextStack(unittest.TestCase): ] result = [] def _exit(*args, **kwds): + """Test metadata propagation""" result.append((args, kwds)) with ContextStack() as stack: for args, kwds in reversed(expected): @@ -328,6 +329,10 @@ class TestContextStack(unittest.TestCase): stack.register(_exit, **kwds) else: stack.register(_exit) + for wrapper in stack._callbacks: + self.assertEqual(wrapper.__name__, _exit.__name__) + self.assertEqual(wrapper.__doc__, _exit.__doc__) + self.assertEqual(result, expected) def test_register_exit(self): exc_raised = ZeroDivisionError