Inheriting doc strings. What are the options?
Michele Simionato
mis6 at pitt.edu
Sat May 3 11:12:00 EDT 2003
Chad Netzer <cnetzer at mail.arc.nasa.gov> wrote in message news:<mailman.1051912806.29766.python-list at python.org>...
> I'd like derived classes to inherit the docstrings of their base
> classes, unless overridden. Or at least, a simple way to do it
> explicitly (perhaps using metaclasses?)
Warning: very little tested!
def setdocstring(cls,name,bases,dic):
if not dic.get('__doc__'):
cls.__doc__=bases[0].__doc__
class InheritableDocString(object):
class __metaclass__(type):
__init__=setdocstring
class A(InheritableDocString):
"A.__doc__"
class B(A):
pass
print B.__doc__
Michele
More information about the Python-list
mailing list