Commit 41eb7164 authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

[Bug #1576241] Let functools.wraps work with built-in functions

parent d3aad019
......@@ -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
......
......@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment