summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-10-27 16:39:10 +0000
committerAndrew M. Kuchling <amk@amk.ca>2006-10-27 16:39:10 +0000
commit41eb7164df4f779864cfad52e5470286ef4fcb4c (patch)
tree5e910cdadf9af80a4577d4ba5ea8b06a3ca1e572
parentd3aad0199e5a6dc8e4907210daa89fc32bb57c94 (diff)
downloadcpython-git-41eb7164df4f779864cfad52e5470286ef4fcb4c.tar.gz
[Bug #1576241] Let functools.wraps work with built-in functions
-rw-r--r--Lib/functools.py2
-rw-r--r--Lib/test/test_functools.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 1fafb0199a..bb13713a9c 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -32,7 +32,7 @@ def update_wrapper(wrapper,
for attr in assigned:
setattr(wrapper, attr, getattr(wrapped, attr))
for attr in updated:
- getattr(wrapper, attr).update(getattr(wrapped, attr))
+ getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
# Return the wrapper so this can be used as a decorator via partial()
return wrapper
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 8dc185b721..6012f9f855 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -210,6 +210,13 @@ class TestUpdateWrapper(unittest.TestCase):
self.assertEqual(wrapper.attr, 'This is a different test')
self.assertEqual(wrapper.dict_attr, f.dict_attr)
+ def test_builtin_update(self):
+ # Test for bug #1576241
+ def wrapper():
+ pass
+ functools.update_wrapper(wrapper, max)
+ self.assertEqual(wrapper.__name__, 'max')
+ self.assert_(wrapper.__doc__.startswith('max('))
class TestWraps(TestUpdateWrapper):