By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Can you fix up wrapper function argument signatures?

P: n/a
Consider:
>>def negate(func):
.... def wrapper(*args, **kwargs):
.... return not func(*args, **kwargs)
.... return wrapper
....
>>def f(x):
.... return x 10
....
>>g = negate(f)
g(20)
False
>>g(5)
True

Now g has the argument signature of (*args, **kwargs). Pop-up help in
Python
Scripter(which is great by the way) tells me this, as does
>>g.func_code.co_varnames
('args', 'kwargs')

Is there anyway to fix this in negate? I assume that I can't just start
changing things in g.func_code since the bytecodes depend on the order
of variables and lots of other stuff that I don't claim to understand.

Please note: From the new functools module, I see that one can set/update
__module__, __name__, __doc__, and __dict__ using the corresponding
attributes
from the wrapped function; however, none these fix up the argument signature
do they? (I'm still running 2.4, so I haven't tried it.)

Thanks,
Gerard

Nov 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gerard Brunick schrieb:
Consider:
>>def negate(func):
... def wrapper(*args, **kwargs):
... return not func(*args, **kwargs)
... return wrapper
...
>>def f(x):
... return x 10
...
>>g = negate(f)
>>g(20)
False
>>g(5)
True

Now g has the argument signature of (*args, **kwargs). Pop-up help in
Python
Scripter(which is great by the way) tells me this, as does
>>g.func_code.co_varnames
('args', 'kwargs')

Is there anyway to fix this in negate? I assume that I can't just start
changing things in g.func_code since the bytecodes depend on the order
of variables and lots of other stuff that I don't claim to understand.

Please note: From the new functools module, I see that one can set/update
__module__, __name__, __doc__, and __dict__ using the corresponding
attributes
from the wrapped function; however, none these fix up the argument
signature
do they? (I'm still running 2.4, so I haven't tried it.)
You can use Michele Simionato's decorator-module.

http://www.phyast.pitt.edu/~micheles...mentation.html

HTH,

Diez
Nov 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.