I'm still new to the technical abilities of Python so help me if I misunderstand the current capabilities. I'd like to see the reload feature of Python enhanced so it can replace the methods for existing class instances, references to methods, and references to functions. Here's the scenario. Let's say you want to use Python as a macro language. Currently, you can bind a Python function to a key or menu (better do it by name and not reference). That's what most apps need. However, an advanced app like SlickEdit would have classes instances for modeless dialogs (including tool windows) and other data structures. There are also callbacks which would preferably need to be references to functions or methods. With the current implementation you would have to close and reopen dialogs. In other cases, you would need to exit SlickEdit and restart. While there always will be cases where this is necessary, I can tell you from experience that this is a great feature to have since Slick-C does this. I suspect that there are other scenarios that users would like this capability for. Java and C# support something like this to a limited extent when you are debugging. This capability could be a reload option. Their could be cases where one might want the existing instances to use the old implementation. You wouldn't need this to be an option for me. There will always be cases where you have to restart because you made too many changes. ____________________________________________________________________________________ Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting
On 9/29/07, Joseph Maurer <clarkksv@yahoo.com> wrote:
I'd like to see the reload feature of Python enhanced so it can replace the methods for existing class instances, references to methods, and references to functions.
I'd be surprised if there's anyone out there who really doesn't want a better reload(). The real question is who's going to figure out how to implement it. ;-) STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy
"Joseph Maurer" <clarkksv@yahoo.com> wrote in message news:844399.5421.qm@web58901.mail.re1.yahoo.com... | I'd like to see the reload feature of Python enhanced so it can replace the methods for existing class instances, references to methods, and references to functions. I think would we could get farther by restricting concern to replacing class attributes so that existing class instances would use their new definitions. As I understand, the problem is this. After somemod is imported, 'import somemod' simply binds 'somemod' to the existing module object, while 'reload somemod' replaces the module object with a new object with all new contents, while references to objects within the old module object remain as are. So I propose this. 'Reclass somemod' (by whatever syntax) would execute the corresponding code in a new namespace (dict). But instead of making that dict the __dict__ attribute of a new module, reclass would match class names with the existing __dict__, and replace the class.__dict__ attributes, so that subsequent access to class attributes, including particularly methods, would get the new versions. In other words use the existing indirection involved in attribute access. New classes could simple be added. Deleted classes could be disabled, but this really requires a restart after editing files that reference such classes, so deleting classes should not be done for the restricted reload uses this idea is aimed at. It would probably be possible to modify function objects (replace func_code, etc), but this is more difficult. It is simpler, at least for a beginning, to require that functions be put within a class when reclassing is anticipated. Terry Jan Reedy
On 9/29/07, Terry Reedy <tjreedy@udel.edu> wrote:
"Joseph Maurer" <clarkksv@yahoo.com> wrote in message news:844399.5421.qm@web58901.mail.re1.yahoo.com... | I'd like to see the reload feature of Python enhanced so it can replace the methods for existing class instances, references to methods, and references to functions.
I think would we could get farther by restricting concern to replacing class attributes so that existing class instances would use their new definitions.
As I understand, the problem is this. After somemod is imported, 'import somemod' simply binds 'somemod' to the existing module object, while 'reload somemod' replaces the module object with a new object with all new contents, while references to objects within the old module object remain as are.
Actually, the way reload works is that it takes the module object from sys.modules, and then re-initializes mod.__dict__ (this is why import loaders must use any pre-existing module's __dict__ when loading). So the module object itself is not replaced, it's just that it's __dict__ is mutated in-place. -Brett
On 9/29/07, Joseph Maurer <clarkksv@yahoo.com> wrote:
I'd like to see the reload feature of Python enhanced so it can replace the methods for existing class instances, references to methods, and references to functions.
Guido did some work on this (as xreload) for Py3K, but gave up for the moment. In the meantime, you can sometimes get a bit closer with indirection. Instead of from othermod import anobject # won't notice if anobject is replaced later use import othermod ... othermod.anobject # always looks up the current anobject That said, subclasses and existing instances generally don't use indirection, because it is slower; replacing bound methods will almost certainly always require at least the moral equivalanent of reloading the dialog after reloading the module. -jJ
participants (5)
-
Brett Cannon
-
Jim Jewett
-
Joseph Maurer
-
Steven Bethard
-
Terry Reedy