Steven D'Aprano a écrit :
I have some code that currently takes four different classes, A, B, C and D, and subclasses each of them in the same way:

class MyA(A):
    def method(self, x):
        result = super(MyA, self).method(x)
        if result == "spam":
            return "spam spam spam"
        return result
    # many more methods overloaded


class MyB(B):
    def method(self, x):
        result = super(MyB, self).method(x)
        if result == "spam":
            return "spam spam spam"
        return result
    # many more methods overloaded


If that's really what your code is doing - I mean, calling the super() implementation, checking the result and eventually returning something else instead - then a simple decorator might be enough... Could even be "applied" by the metaclass.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to