Nick Coghlan added the comment: 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 ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23764> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com