A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-September/048615.html below:

[Python-Dev] decorator support

[Python-Dev] decorator support"Martin v. Löwis" martin at v.loewis.de
Sun Sep 5 11:16:45 CEST 2004
Raymond Hettinger wrote:
> So, it would be nice if there were some support for carrying forward the
> argspec to inform help(), calltips(), and inspect().

What were you thinking of? I could imagine a predefined class, such as

class copyfuncattrs:
     def __init__(self, f):
         self.f = f

     def __call__(self, func):
         res = self.f(func)
         res.__name__ = func.__name__
         res.__doc__ = func.__doc__
         res.__dict__.update(func.__dict__)
         return res

This could be used to define a decorator

@copyfuncattrs
def trace(f):
     def do_trace(*args):
         print "invoking", f.__name__, args
         return f(*args)
     return do_trace

which in turn could be used to decorate a function

@trace
def hello():
     "Print a nice greeting"
     print "Hello, world"

which in turn could be called and inspected

hello()
print hello.__doc__

Then, the question is where copyfuncattrs should live, and I would
object that to be yet another builtin.

Regards,
Martin
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4