[Patches] [ python-Patches-1212921 ] option to allow reload to affect existing instances

SourceForge.net noreply at sourceforge.net
Thu Sep 1 11:38:40 CEST 2005


Patches item #1212921, was opened at 2005-06-01 19:18
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1212921&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Brett Rosen (bdrosen)
Assigned to: Nobody/Anonymous (nobody)
Summary: option to allow reload to affect existing instances

Initial Comment:
One of the commonly asked questions (especially when
developing
GUI apps) is how do I reload a modified python file and
have
the existing instances automatically get the changed
behavior.
(this greatly speeds up the development cycle.)
 
Unfortunately python doesn't support this without having
to do the work yourself. To rectify this, I've implemented
smart reloading as detailed below:

Smart reloading is defined as applying modified code to
your
already instantiated objects on reload.

Supporting smart reloading for python:

Make sure that you execute python with the -r flag if
you want smart reloading to work by default. The semantics
of reload work as normal

The normal model has been expanded by adding two special
attributes to classes:

1 __pqname__ : This is used to give a hint as to our
context if we are a nested
class (top level classes don't need to use it) It
specifies the parent
hierarchy, excluding the module name. ie:

    class outer(object):
        class middle(object):
            __pqname__ = "outer"
            class inner(object):
                __pqname__ = "outer.middle"

excluding this for inner classes can lead to confusion
if you have multiple inner classes
with the same name.

2 __reloadMode__ : This can have one of the 3 values -
"overlay", "clear" and "disable"

 a) clear is the default if you are in reload mode (-r)
and you don't specify anything.
    The behavior here is to clear the class dictionary
before doing the reload of the class.
 b) overlay works like clear except that it doesn't
clear the class dictionary first.
 c) disable gives you the classic python behavior and
is the default if you are not in
    reload mode (no -r specified)
 

When using this you almost never want to reuse class
names in a module file. 
For example:

class foo(object):
...


class foo(object):
...

would be bad. The second class foo replaces the first
one, although
with overlay it could be used as syntactic sugar for
adding new methods
to an existing class.






----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2005-09-01 10:38

Message:
Logged In: YES 
user_id=6656

My first thought is to plug my recipe:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164

In fact, this seems pretty similar to what the patch does, on a quick skim.

Given that the bulk of the functionality can be implemented in Python, I'm 
not sure *I* support the further complication of type_new for this.

----------------------------------------------------------------------

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-08-31 23:29

Message:
Logged In: YES 
user_id=1188172

Does anyone care to give a quick, obliterative judgement
about this?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1212921&group_id=5470


More information about the Patches mailing list