Re: decorating functions with generic signatures (not for the faint of heart)

2005-04-08 Thread Michele Simionato
Yes, this is essentially the same idea. You compile the codestring to bytecode, whereas I just evalue the codestring to a lambda function. We are essentially implementing a runtime macro by hand. I wonder if there is any alternative approach to get the same result, without manipulation of the sourc

Re: decorating functions with generic signatures (not for the faint of heart)

2005-04-08 Thread Thomas Heller
"Michele Simionato" <[EMAIL PROTECTED]> writes: > I have realized today that defining decorators for functions > with generic signatures is pretty non-trivial. I've not completely read your post ;-), but I assume you're trying to do something that I've also done some time ago. Maybe the following

Re: decorating functions with generic signatures (not for the faint of heart)

2005-04-08 Thread Michele Simionato
I said it was very little tested! ;) This should work better: # def _signature_gen(varnames, n_default_args, n_args, rm_defaults=False): n_non_default_args = n_args - n_default_args non_default_names = varnames[:n_non_default_args] default_names = varnames[n_non_default_args:n_args]

decorating functions with generic signatures (not for the faint of heart)

2005-04-08 Thread Michele Simionato
I have realized today that defining decorators for functions with generic signatures is pretty non-trivial. Consider for instance this typical code: # def traced_function(f): def newf(*args, **kw): print "calling %s with args %s, %s" % (f.__name__, args, kw) return f(*args, *