This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: functools.WRAPPER_ASSIGNMENTS should include __annotations__
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: David Caro, eric.araujo, pitrou, rhettinger, terrence
Priority: normal Keywords: patch

Created on 2010-05-24 21:20 by terrence, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
functools-wrapper-assign-annotations.diff terrence, 2010-05-24 21:20 Patch to add __annotations__ to WRAPPER_ASSIGNMENTS
functools-wrapper-assign-annotations.diff terrence, 2010-05-24 21:48 Improved patch with documentation fixed to match.
functools-wrapper-assign-annotations.diff terrence, 2010-06-17 01:04 Improved patch with documentation and tests
Pull Requests
URL Status Linked Edit
PR 21392 open David Caro, 2020-07-08 09:16
Messages (13)
msg106394 - (view) Author: Terrence Cole (terrence) Date: 2010-05-24 21:20
__annotations__ should be included in the set of attributes copied by default to a wrapped method.

An example of the problem:
>>> from functools import wraps
>>> def mydecorator(fn):
...     @wraps(fn)
...     def inner(*args, **kwargs):
...         return fn(*args, **kwargs)
...     return inner
>>> @mydecorator
... def foo(a:int, b:str):
...     pass
>>> foo.__annotations__

With the included fix:
>>> foo.__annotations__
{'a': <class 'int'>, 'b': <class 'str'>}
msg106396 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-05-24 21:33
The patch is fine. Can you check if some doc has to be updated to mention that? (files under Doc and docstrings in

Removing 3.1 since this is a new feature, and 3.3 since 3.2 is not frozen.
msg106402 - (view) Author: Terrence Cole (terrence) Date: 2010-05-24 21:48
Thank you for looking it over!  The updated patch adds __annotations__ to the documentation where the value of WRAPPER_ASSIGNMENTS is given.  I think it would be nice if the documentation showed WRAPPER_ASSIGNMENTS and WRAPPER_UPDATES in their own section, but that would probably merit a separate issue to fix, if it is even worth bothering with.
msg107759 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-13 22:13
Patch looks good to me. Could you add some tests to Lib/test/ to check that annotations are really copied?

(3.2 is not frozen, adjusting versions)
msg107974 - (view) Author: Terrence Cole (terrence) Date: 2010-06-17 01:04
Alright, I've added several tests.  I also modified update_wrapper to not copy missing attributes (like __annotations__ on builtin methods) -- see issue 1576241.

(I also finally see what you mean with removing 3.3 from the versions list.  Sorry I didn't grok that before.)
msg112851 - (view) Author: Terrence Cole (terrence) Date: 2010-08-04 18:18
Is there still a chance to get this fix in 3.2?
msg112852 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-04 18:29
The patch is now committed in py3k (r83731). Thanks for your contribution!
msg112856 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-08-04 18:38
This should probably be backported to 3.1
msg112858 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-04 18:48
> This should probably be backported to 3.1

Well, I think this is technically a new feature. If someone wants to
backport it, then fine, but I don't think there's much point in doing
msg112860 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-08-04 18:52
Okay, I'll do it.

The intention of wrapper assignments was to wrap all of the standard attributes, so the omission of __annotations__ is a bug.
msg112874 - (view) Author: Terrence Cole (terrence) Date: 2010-08-04 19:50
Awesome!  I greatly appreciate the 3.1 backport, as that's what I'm going to be using for the foreseeable future.
msg112903 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-04 21:42
Thanks for sticking with this Terrence, it fell off my radar. Thanks Antoine for the commit.
msg113220 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-08-08 00:57
Backported to Py3.1 in r83807
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 53060
2020-07-08 09:16:01David Carosetnosy: + David Caro

pull_requests: + pull_request20539
2010-08-08 00:57:27rhettingersetstatus: open -> closed

messages: + msg113220
2010-08-04 21:42:36eric.araujosetmessages: + msg112903
versions: + Python 3.1
2010-08-04 19:50:04terrencesetmessages: + msg112874
versions: + Python 3.2, - Python 3.1
2010-08-04 18:52:26rhettingersetstatus: closed -> open
assignee: rhettinger
messages: + msg112860

versions: + Python 3.1, - Python 3.2
2010-08-04 18:48:47pitrousetmessages: + msg112858
2010-08-04 18:38:51rhettingersetnosy: + rhettinger
messages: + msg112856
2010-08-04 18:29:02pitrousetstatus: open -> closed

nosy: + pitrou
messages: + msg112852

resolution: fixed
2010-08-04 18:18:52terrencesetmessages: + msg112851
2010-06-17 01:04:17terrencesetfiles: + functools-wrapper-assign-annotations.diff

messages: + msg107974
2010-06-13 22:13:56eric.araujosetstage: test needed
messages: + msg107759
versions: - Python 3.3
2010-05-24 21:48:53terrencesetfiles: + functools-wrapper-assign-annotations.diff

messages: + msg106402
versions: + Python 3.3
2010-05-24 21:33:00eric.araujosetnosy: + eric.araujo

messages: + msg106396
versions: - Python 3.1, Python 3.3
2010-05-24 21:20:57terrencecreate