mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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)
This commit is contained in:
parent
632a0c1476
commit
9887683f74
4 changed files with 65 additions and 2 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue