Changing base class of a big hierarchy
John J. Lee
jjl at pobox.com
Sun Aug 3 07:31:37 EDT 2003
I'm trying to change a base class of a big class hierarchy. The
hierarchy in question is 4DOM (from PyXML). 4DOM has an FtNode class
that defines __getattr__ and __setattr__ that I need to override.
Lots of classes derive from FtNode, often through further base
classes, eg.
HTMLDirectoryElement --> HTMLElement --> Element --> FtNode
There are many leaf classes like HTMLDirectoryElement. The problem
is, I need to get new classes identical to the leaf classes, but
deriving from BrowserFtNode:
class BrowserFtNode(FtNode):
def __init__(self, *args, **kwargs):
...
def __getattr__(self, name):
...
def __setattr__(self, name, value):
...
Obviously, I don't want to manually derive from every damned leaf
class. I want to say "give me a new class hierarchy just like this
one, but derived from BrowserFtNode instead of FtNode". I also don't
want to actually mutate the xml.dom module, of course because other
code may be using it.
What's the easiest way to do that?
Maybe deep-copying the module or something, then fiddling with
__bases__?? Or a metaclass?
While I'm on the subject, does anybody have code to get a list of all
classes in a package that derive from a particular class? Or
something I could use to do that easily?
John
More information about the Python-list
mailing list