MixIn method to call the method it overrides: how?
Mac
idontneednostinkinid at yahoo.com
Sat Jun 18 08:28:02 EDT 2005
I have a MixIn class which defines a method foo(), and is then mixed in
with another class by being prepended to that class's __bases__ member,
thus overriding that class's definition of foo(). In my application
though it is necessary for the MixIn's foo() to call the overridden
foo(). How can I do this?
My current hack is to do this:
def foo(): # MixIn's method
orig_bases = self.__class__.__bases__
bases = list(orig_bases)
bases.remove(OptEdgeCache)
self.__class__.__bases__ = tuple(bases)
foo_orig = self.foo
self.__class__.__bases__ = orig_bases
# other stuff here...
Is there a better way? Does the above even work as I think it does?
More information about the Python-list
mailing list