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.

Author David Caro
Recipients David Caro
Date 2020-07-07.17:29:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594142955.77.0.852569543435.issue41231@roundup.psfhosted.org>
In-reply-to
Content
In version 3.2, bpo-8814 introduced copying the __annotations__ property from the wrapped function to the wrapper by default.

That would be the desired behavior when your wrapper function has the same signature than the function it wraps, but in some cases (for example, with the contextlib.asynccontextmanager function) the return value is different, and then the __annotations__ property will have invalid information:

In [2]: from contextlib import asynccontextmanager                                                                                                            

In [3]: @asynccontextmanager 
   ...: async def mytest() -> int: 
   ...:     return 1 
   ...:                                                                                                                                                       

In [4]: mytest.__annotations__                                                                                                                                
Out[4]: {'return': int}


I propose changing the behavior of wraps, to only assign the __annotations__ by default if there's no __annotations__ already in the wrapper function, that would fit most default cases, but would allow to preserve the __annotations__ of the wrapper function when the types are explicitly specified, allowing now to change the contextlib.asynccontextmanager function with the proper types (returning now an AsyncContextManager) and keep the __annotation__ valid.

I'll try to get a POC and attach to the issue, but please comment with your ideas too.
History
Date User Action Args
2020-07-07 17:29:15David Carosetrecipients: + David Caro
2020-07-07 17:29:15David Carosetmessageid: <1594142955.77.0.852569543435.issue41231@roundup.psfhosted.org>
2020-07-07 17:29:15David Carolinkissue41231 messages
2020-07-07 17:29:15David Carocreate