summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2010-08-17 06:17:18 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2010-08-17 06:17:18 (GMT)
commit9887683f7407b2d4ec0e0ff1ff9b9a26137d0724 (patch)
tree07c1120d84c6a4f83ede41bccd2db5d08acb7ee4 /Lib/functools.py
parent632a0c1476bce66a2226ce9b103d0ef96e739a2c (diff)
downloadcpython-9887683f7407b2d4ec0e0ff1ff9b9a26137d0724.zip
cpython-9887683f7407b2d4ec0e0ff1ff9b9a26137d0724.tar.gz
cpython-9887683f7407b2d4ec0e0ff1ff9b9a26137d0724.tar.bz2
Document and test the resolution of issue 3445 (tolerate missing attributes in functools.update_wrapper, previously implemented as a side effect of the __annotations__ copying patch) and implement issue 9567 (add a __wrapped__ attribute when using update_wrapper)
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index c2c2282..bd1334b 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -38,9 +38,14 @@ def update_wrapper(wrapper,
are updated with the corresponding attribute from the wrapped
function (defaults to functools.WRAPPER_UPDATES)
"""
+ wrapper.__wrapped__ = wrapped
for attr in assigned:
- if hasattr(wrapped, attr):
- setattr(wrapper, attr, getattr(wrapped, attr))
+ try:
+ value = getattr(wrapped, attr)
+ except AttributeError:
+ pass
+ else:
+ setattr(wrapper, attr, value)
for attr in updated:
getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
# Return the wrapper so this can be used as a decorator via partial()