Questions re subclassing at "load time"

Michele Simionato mis6 at
Mon Jun 23 14:23:17 CEST 2003

"Edward K. Ream" <edreamleo at> wrote in message news:<vfb68sik4m4v86 at>...
> There appears to be an easy way for plugins to override classes in an app.
> This seems like a spectacular capability.  I'd like your comments on the
> following scheme.
> 1. In my app, a plugin is simply a .py file that gets "loaded", i.e.
> imported, at a particular time while my app is starting up.  My app loads
> plugins before creating any objects whose classes may be modified by
> plugins.
> 2. My app defines each class that may be subclassed by plugins using the
> following pattern:
> class aCoreClass:
>     << methods of aCoreClass >>
> class aClass (aCoreClass):
>     pass
> 3. Except as above, all code in my app refers to aClass, not aCoreClass.
> 4. To modify aClass, a plugin does the following at the outer level:
> import aClass  # The file containing aCoreClass and aClass.
> class myNewClass (aClass.aCoreClass):
>     << overriding methods of aCoreClass >>
> aClass.aClass = myNewClass # change what an aClass is!

I don't see anything bad in using Python dynamism, as long as you properly
document your code. I think you could do something similar with multiple
inheritance, and your problem remind me of a paper on mixins by Chuck
Esterbrook that you may find interesting:



More information about the Python-list mailing list