]> granicus.if.org Git - python/commitdiff
[Bug #1576241] Let functools.wraps work with built-in functions
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 27 Oct 2006 16:42:19 +0000 (16:42 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 27 Oct 2006 16:42:19 +0000 (16:42 +0000)
Lib/functools.py
Lib/test/test_functools.py
Misc/NEWS

index 8783f08488e181715d98a1f514db577180c167f5..96430365c9a1ee4c10e9fa89ed7326a19c357d8a 100644 (file)
@@ -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
 
index 8dc185b721033844b6c24fc338c9f3c13890157c..6012f9f8551803eb4ef7c3c2716c70f51974b457 100644 (file)
@@ -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):
 
index a1033bf378d51e7dacefd66f93a715b6eecad26d..13f52a78e7b5c6a634430cd595908e75d01fc662 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -105,6 +105,8 @@ Library
 - Bug #1565661: in webbrowser, split() the command for the default
   GNOME browser in case it is a command with args.
 
+- Bug #1576241: fix functools.wraps() to work on built-in functions.
+
 - Fix a bug in traceback.format_exception_only() that led to an error
   being raised when print_exc() was called without an exception set.
   In version 2.4, this printed "None", restored that behavior.