Greg Ewin wrote:
What you suggest sounds like it ought to be possible, at first sight, since Python function objects are already containers with a reference to another object that holds the function's code.
The problem will be figuring out when you're redefining a function, because the process of loading a module is a very dynamic one in Python. Defining functions and classes is done by executing code, not by statically analysing declarations as a C compiler does.
My implementation is definitely a high level scetch.
The kind of issues you are bringing up is exactly the kind of thing I'm looking for. If there are more, lets see them.
Would temporarily marking the module with "replace" work? I would think that when the function is defined, it has access to the module (because it is adding to its dictionary) and it could check for the "replace" attribute. I'm assuming a certain sequence of execution here since the "replace" attribute would have to removed after the function/method code was executed/loaded. Anyone who knows that this isn't the case, please shoot this down.
Another post I read proposed a Reclass feature that only worked for classes. Given the macro language scenario, you definitely need functions too.
Tonight's top picks. What will you watch tonight? Preview the hottest shows on Yahoo! TV. http://tv.yahoo.com/
Joseph Maurer wrote:
Another post I read proposed a Reclass feature that only worked for classes.
You could probably do something similar for functions. Go through the new module, and when you find a function, look to see whether there is something defined in the old module that's also a function. If so, replace the old function's code object with that of the new one.
If you extend this to functions inside classes as well, you may even be able to catch bound methods that have been squirrelled away as well.
-- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | firstname.lastname@example.org +--------------------------------------+