Questions re subclassing at "load time"

Steven Taschuk staschuk at telusplanet.net
Sun Jun 22 14:05:26 EDT 2003


Quoth Edward K. Ream:
  [...in app...]
> class aCoreClass:
>     << methods of aCoreClass >>
> 
> class aClass (aCoreClass):
>     pass
  [...in plugin...]
> class myNewClass (aClass.aCoreClass):
>     << overriding methods of aCoreClass >>
> 
> aClass.aClass = myNewClass # change what an aClass is!
  [...]
> 1. Is this scheme completely safe?  Anything to watch out for?

One thing occurs to me: different plugins can't change the same
class; the second plugin loaded will simply nuke the previous
plugin's version of aClass.

An alternative: in the plugin, write
    class myNewClass(aClass.aClass):  # instead of aClass.aCoreClass
Then any previous plugin's version of aClass will be subclassed by
the new version.  If the new version plays well with others (e.g.,
extends methods rather than overriding them) then all plugins will
get their say in the behaviour of aClass.

In this alternative, the exact result still depends on the order
in which plugins are loaded.  Whether this is acceptable obviously
depends on what sorts of changes the plugins make.

-- 
Steven Taschuk                               staschuk at telusplanet.net
"What I find most baffling about that song is that it was not a hit."
                                          -- Tony Dylan Davis (CKUA)





More information about the Python-list mailing list