Inheriting methods but over-riding docstrings

Steven D'Aprano steve at
Sat Jan 16 18:55:11 CET 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?


More information about the Python-list mailing list