[Python-checkins] r52477 - in python/branches/release25-maint: Lib/functools.py Lib/test/test_functools.py Misc/NEWS

andrew.kuchling python-checkins at python.org
Fri Oct 27 18:42:20 CEST 2006


Author: andrew.kuchling
Date: Fri Oct 27 18:42:19 2006
New Revision: 52477

Modified:
   python/branches/release25-maint/Lib/functools.py
   python/branches/release25-maint/Lib/test/test_functools.py
   python/branches/release25-maint/Misc/NEWS
Log:
[Bug #1576241] Let functools.wraps work with built-in functions

Modified: python/branches/release25-maint/Lib/functools.py
==============================================================================
--- python/branches/release25-maint/Lib/functools.py	(original)
+++ python/branches/release25-maint/Lib/functools.py	Fri Oct 27 18:42:19 2006
@@ -32,7 +32,7 @@
     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
 

Modified: python/branches/release25-maint/Lib/test/test_functools.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_functools.py	(original)
+++ python/branches/release25-maint/Lib/test/test_functools.py	Fri Oct 27 18:42:19 2006
@@ -210,6 +210,13 @@
         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):
 

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Fri Oct 27 18:42:19 2006
@@ -105,6 +105,8 @@
 - 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.


More information about the Python-checkins mailing list