decorators, function signature, and help()
Peter Otten
__peter__ at web.de
Tue Aug 10 08:15:18 EDT 2004
After a week or so I'm finally getting accustomed to the pie-pre-def syntax.
Consider a simple-minded decorator that doesn't care about the signature of
the function it wraps:
>>> def noisy(f):
... def g(*args, **kw):
... print f.__name__
... return f(*args, **kw)
... return g
...
>>> @noisy
... def naught():
... "does nothing"
...
>>> naught()
naught
Now help() is less than helpful:
>>> help(naught)
Help on function g:
g(*args, **kw)
While the docstring can easily be copied and might even be prefixed
g.__doc__ = "@noisy\n" + f.__doc__
the name currently can not. I do not see a way to preserve the signature
either. It seems that when decoration is a built-in feature that even has
syntax support it should play nice in these cases by default. Any ideas?
Could there be a smooth way to quote an argument list, e. g:
def f(a, b, c): pass
def g(/*same args as f*/): pass
Peter
More information about the Python-list
mailing list