mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue 8814: functools.wraps() did not copy __annotations__.
This commit is contained in:
parent
f56c9cd30d
commit
c6d80c1bef
5 changed files with 17 additions and 7 deletions
|
|
@ -12,7 +12,7 @@ from _functools import partial, reduce
|
|||
# update_wrapper() and wraps() are tools to help write
|
||||
# wrapper functions that can handle naive introspection
|
||||
|
||||
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
|
||||
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__', '__annotations__')
|
||||
WRAPPER_UPDATES = ('__dict__',)
|
||||
def update_wrapper(wrapper,
|
||||
wrapped,
|
||||
|
|
@ -30,7 +30,8 @@ def update_wrapper(wrapper,
|
|||
function (defaults to functools.WRAPPER_UPDATES)
|
||||
"""
|
||||
for attr in assigned:
|
||||
setattr(wrapper, attr, getattr(wrapped, attr))
|
||||
if hasattr(wrapped, attr):
|
||||
setattr(wrapper, attr, getattr(wrapped, attr))
|
||||
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