[issue41232] Python `functools.wraps` doesn't deal with defaults correctly

Gregory P. Smith report at bugs.python.org
Sat May 1 21:03:59 EDT 2021


Gregory P. Smith <greg at krypto.org> added the comment:

I'm working on a more specialized case of this for functools.lru_cache in bpo-issue44003.  But I believe this issue also makes sense.  It is basically suggesting that __defaults__ and __kwdefaults__ should be included in the default set of assigned= attributes that functools.update_wrapper applies.

The argument in favor of this is that it already has __annotations__ in the default set.  With that, the default isn't really correct for use on any decorator that modifies the meaning or overall call signature of the function if it happens to have annotations.  as __annotations__ and __defaults__ and __kwdefaults__ are all abstract callable introspection interfaces.

>From Python's perspective some may call each of these an Enhancement rather than a Bugfix.  I'm fine with that.  It doesn't come up super often but would make Python things more consistent if it were done.

Your PR makes sense to me, though we'll need to understand and fix that test failure you identified where it appears to be potentially testing for the wrong thing (I haven't studied it enough study to say yet).

----------
nosy: +gregory.p.smith

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41232>
_______________________________________


More information about the Python-bugs-list mailing list