-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functools.WRAPPER_ASSIGNMENTS should include __annotations__ #53060
Comments
__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'>} |
The patch is fine. Can you check if some doc has to be updated to mention that? (files under Doc and docstrings in functools.py). Removing 3.1 since this is a new feature, and 3.3 since 3.2 is not frozen. |
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. |
Patch looks good to me. Could you add some tests to Lib/test/test_functools.py to check that annotations are really copied? (3.2 is not frozen, adjusting versions) |
Alright, I've added several tests. I also modified update_wrapper to not copy missing attributes (like __annotations__ on builtin methods) -- see bpo-1576241. (I also finally see what you mean with removing 3.3 from the versions list. Sorry I didn't grok that before.) |
Is there still a chance to get this fix in 3.2? |
The patch is now committed in py3k (r83731). Thanks for your contribution! |
This should probably be backported to 3.1 |
Well, I think this is technically a new feature. If someone wants to |
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. |
Awesome! I greatly appreciate the 3.1 backport, as that's what I'm going to be using for the foreseeable future. |
Thanks for sticking with this Terrence, it fell off my radar. Thanks Antoine for the commit. |
Backported to Py3.1 in r83807 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: