Inheriting methods but over-riding docstrings

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Jan 16 12:55:11 EST 2010


I have a series of subclasses that inherit methods from a base class, but 
I'd like them to have their own individual docstrings. The obvious 
solution (other than copy-and-paste) is this:


class Base(object):
    colour = "Blue"
    def parrot(self):
        """docstring for Base"""
        return "Norwegian %s" % self.colour


class SubClass(Base):
    colour = "Red"
    def parrot(self):
        """docstring for Subclass"""
        return super(Subclass, self).parrot()


but that adds an awful lot of boilerplate to my subclasses. Are there any 
other good solutions to this problem?



-- 
Steven



More information about the Python-list mailing list