[Python-Dev] Proposed tweaks to functools.wraps (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Wed Aug 11 23:21:32 CEST 2010


On Thu, Aug 12, 2010 at 12:12 AM, Simon Cross <hodgestar+pythondev at gmail.com> wrote:

Yes. But it's more common for the original function to have be modified in some way. e.g.:

def autodoc(f):  f.doc += documentargs(f)  return f @autodoc def f(x, y): """Add two numbers""" return x + y And then f.wrapped is not particularly useful because the original function no longer exists and odd things will happen. For example, in the code above autodoc(f.wrapped).doc will not equal f.doc.

There's no call to wraps or update_wrapper here, so f.wrapped won't exist.

I guess my description of the problem wasn't clear. I meant:

def debug(*args, **kwargs)  print args, kwargs def mock(f):  return debug @mock def plus(a, b): return a + b @mock def prod(a, b):  return a * b

Again, without any calls to wraps or update_wrapper, plus.wrapped and prod.wrapped won't exist.

However, as I noted before, these kinds of scenario are the reason we decided that building this feature directly into the decorator machinery wasn't a good idea.

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list