mirror of
https://github.com/python/cpython.git
synced 2025-08-21 17:25:34 +00:00
[Bug #1576241] Let functools.wraps work with built-in functions
This commit is contained in:
parent
d2ee30b485
commit
3d6a834e29
3 changed files with 10 additions and 1 deletions
|
@ -32,7 +32,7 @@ def update_wrapper(wrapper,
|
||||||
for attr in assigned:
|
for attr in assigned:
|
||||||
setattr(wrapper, attr, getattr(wrapped, attr))
|
setattr(wrapper, attr, getattr(wrapped, attr))
|
||||||
for attr in updated:
|
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 the wrapper so this can be used as a decorator via partial()
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,13 @@ class TestUpdateWrapper(unittest.TestCase):
|
||||||
self.assertEqual(wrapper.attr, 'This is a different test')
|
self.assertEqual(wrapper.attr, 'This is a different test')
|
||||||
self.assertEqual(wrapper.dict_attr, f.dict_attr)
|
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):
|
class TestWraps(TestUpdateWrapper):
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,8 @@ Library
|
||||||
- Bug #1565661: in webbrowser, split() the command for the default
|
- Bug #1565661: in webbrowser, split() the command for the default
|
||||||
GNOME browser in case it is a command with args.
|
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
|
- Fix a bug in traceback.format_exception_only() that led to an error
|
||||||
being raised when print_exc() was called without an exception set.
|
being raised when print_exc() was called without an exception set.
|
||||||
In version 2.4, this printed "None", restored that behavior.
|
In version 2.4, this printed "None", restored that behavior.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue