You can abuse properties for this purpose. Properties contain the receiver, installer, uninstaller, and documentation string. It would be naive to get very verbose:
class C: def __init__(self): self._x = None @property def x(self): """Docstring goes here.""" return self._x @x.setter def x(self, value): self._x = value @x.deleter def x(self): del self._x
Then you will have a documentation line owned by Cx:
In [24]: print(Cx__doc__) Docstring goes here.
It is quite difficult to do this for many attributes, but you can imagine the helper function myprop:
def myprop(x, doc): def getx(self): return getattr(self, '_' + x) def setx(self, val): setattr(self, '_' + x, val) def delx(self): delattr(self, '_' + x) return property(getx, setx, delx, doc) class C: a = myprop("a", "Hi, I'm A!") b = myprop("b", "Hi, I'm B!") In [44]: c = C() In [46]: cb = 42 In [47]: cb Out[47]: 42 In [49]: print(Cb__doc__) Hi, I'm B!
Then, calling the Pythons interactive help will give:
Help on class C in module __main__: class C | Data descriptors defined here: | | a | Hi, I'm A! | | b | Hi, I'm B!
what I think should be pretty much what you are after.
Edit : Now I understand that we can possibly avoid having to pass the first argument to myprop at all, because the internal name does not matter. If subsequent calls to myprop can somehow communicate with each other, it can automatically select a long and unlikely internal attribute name. I'm sure there are ways to implement this, but I'm not sure if they are worth it.