A python docstring must be given as a literal string; but sometimes it's useful to have similar docstrings for several functions (e.g., different constructors), or several access methods might accept the same list of arguments (and then rely on the same hidden method), so it would be nice to use the same description everywhere. For such cases I can construct a docstring by assigning to __doc__
, which I do by means of a simple decorator. The system works very nicely (in python 2), and I'm pleased with how simple, clear and well-encapsulated it is.
The question: Is this a good idea? In particular, are there tools that would be confused by this set-up (e.g., anything that extracts docstrings from the source rather than from the bytecode). Is the solution still going to work in python 3? Are there other reasons or circumstances that would make this inadvisable?