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 ncoghlan
Recipients ncoghlan, productivememberofsociety666, r.david.murray, rhettinger
Date 2015-03-26.00:28:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427329703.99.0.72953058912.issue23764@psf.upfronthosting.co.za>
In-reply-to
Content
Full example showing the functools.partial based implementation:

>>> def wrapper(func):
...     return functools.wraps(func)(functools.partial(func))
... 
>>> def to_be_wrapped(x):
...     pass
...                                                                     
>>> import inspect
>>> inspect.getargspec(wrapper(to_be_wrapped))
ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None)

Th usage of functools.partial is also what gives the PyPI decorator module eager validation of the argument structure, even if the original function is never actually called.

When you use the pass-through "*args, **kwds" signature on a wrapper function it really is just a pass-through - even setting __signature__ won't get the *interpreter* to change the way it processes the arguments, as that's baked directly into the compiled code object:

>>> def f(*args, **kwds):
...     pass
... 
>>> import dis
>>> dis.show_code(f)
Name:              f
Filename:          <stdin>
Argument count:    0
Kw-only arguments: 0
Number of locals:  2
Stack size:        1
Flags:             OPTIMIZED, NEWLOCALS, VARARGS, VARKEYWORDS, NOFREE
Constants:
   0: None
Variable names:
   0: args
   1: kwds
History
Date User Action Args
2015-03-26 00:28:24ncoghlansetrecipients: + ncoghlan, rhettinger, r.david.murray, productivememberofsociety666
2015-03-26 00:28:23ncoghlansetmessageid: <1427329703.99.0.72953058912.issue23764@psf.upfronthosting.co.za>
2015-03-26 00:28:23ncoghlanlinkissue23764 messages
2015-03-26 00:28:23ncoghlancreate