473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can you fix up wrapper function argument signatures?

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
1 1179
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Egil M?ller | last post by:
Is there any way to create transparent wrapper objects in Python? I thought implementing __getattribute__ on either the wrapper class or its metaclass would do the trick, but it does not work for...
15
by: Steve Richfield | last post by:
To All, First, some of your replies to me have been posted through DevelopersDex, and these are NOT posted on USENET for the world to see. DevelopersDex appears to be trying to hijack USENET,...
5
by: Rolf Wester | last post by:
Hi, I want to pass a C-function as a function parameter but I don't know how to that correctly. In the example below how would I have to declare the function argument in the my_sort function...
3
by: franco ziade | last post by:
I am stuck :( I am trying to pass the address of a function as an argument to a function (some OS call to launch a task): Example: -------- Declaration of the OS "lunch a Task" LunchTask(...,...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
23
by: I.M. !Knuth | last post by:
A while back, I was mucking around with a recursive function. For brevity's sake, I'll define it like this: int func_recurs(int arg1, int arg2, int prev_pos) { int crnt_pos = 0; int result; ...
1
by: mo | last post by:
I have a C++.net wrapper class to a C++ library... A function takes in a pointer in the wrapper... How do I pass that in C#??? Any help would be appreciated, Thank you. // functions in original...
28
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
3
by: srbakshi | last post by:
Hey all, I'm stuck with the following: The mysql_real_escape_string(conn, to, from, strlen(from)) function does not return the escaped string. So how can I go about writing a wrapper for it so...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.