From 35fd142435a5123d3ce740d14068034dab9ee5ec Mon Sep 17 00:00:00 2001
From: "Phillip J. Eby" <pje@telecommunity.com>
Date: Tue, 28 Mar 2006 00:07:24 +0000
Subject: Fix contextlib not copying function attributes

---
 Lib/contextlib.py           |  1 +
 Lib/test/test_contextlib.py | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index d329087..9c00ef0 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -78,6 +78,7 @@ def contextmanager(func):
     try:
         helper.__name__ = func.__name__
         helper.__doc__ = func.__doc__
+        helper.__dict__ = func.__dict__
     except:
         pass
     return helper
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 7d7f8d2..cd8895e 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -84,6 +84,21 @@ class ContextManagerTestCase(unittest.TestCase):
             raise ZeroDivisionError(999)
         self.assertEqual(state, [1, 42, 999])
 
+    def test_contextmanager_attribs(self):
+        def attribs(**kw):
+            def decorate(func):
+                for k,v in kw.items():
+                    setattr(func,k,v)
+                return func
+            return decorate
+        @contextmanager
+        @attribs(foo='bar')
+        def baz(spam):
+            """Whee!"""
+        self.assertEqual(baz.__name__,'baz')
+        self.assertEqual(baz.foo, 'bar')
+        self.assertEqual(baz.__doc__, "Whee!")
+
 class NestedTestCase(unittest.TestCase):
 
     # XXX This needs more work
-- 
cgit v0.12

