title: How to document class attributes in Python?
body: <p>I'm writing a lightweight class whose attributes are intended to be publicly accessible, and only sometimes overridden in specific instantiations.  There's no provision in the Python language for creating docstrings for class attributes, or any sort of attributes, for that matter.  What is the expected and supported way, should there be one, to document these attributes?  Currently I'm doing this sort of thing:</p>
  
  <pre><code>class Albatross(object):
      """A bird with a flight speed exceeding that of an unladen swallow.
  
      Attributes:
      """
  
      flight_speed = 691
      __doc__ += """
          flight_speed (691)
            The maximum speed that such a bird can attain.
      """
  
      nesting_grounds = "Raymond Luxury-Yacht"
      __doc__ += """
          nesting_grounds ("Raymond Luxury-Yacht")
            The locale where these birds congregate to reproduce.
      """
  
      def __init__(self, **keyargs):
          """Initialize the Albatross from the keyword arguments."""
          self.__dict__.update(keyargs)
  </code></pre>
  
  <p>This will result in the class's docstring containing the initial standard docstring section, as well as the lines added for each attribute via augmented assignment to <code>__doc__</code>.</p>
  
  <p>Although this style doesn't seem to be expressly forbidden in the <a href="http://www.python.org/dev/peps/pep-0257/" rel="noreferrer">docstring style guidelines</a>, it's also not mentioned as an option.  The advantage here is that it provides a way to document attributes alongside their definitions, while still creating a presentable class docstring, and avoiding having to write comments that reiterate the information from the docstring.  I'm still kind of annoyed that I have to actually write the attributes twice; I'm considering using the string representations of the values in the docstring to at least avoid duplication of the default values.</p>
  
  <p>Is this a heinous breach of the ad hoc community conventions?  Is it okay?  Is there a better way?  For example, it's possible to create a dictionary containing values and docstrings for the attributes and then add the contents to the class <code>__dict__</code> and docstring towards the end of the class declaration; this would alleviate the need to type the attribute names and values twice.  <strong>edit</strong>: this last idea is, I think, not actually possible, at least not without dynamically building the entire class from data, which seems like a really bad idea unless there's some other reason to do that.</p>
  
  <p>I'm pretty new to python and still working out the details of coding style, so unrelated critiques are also welcome.</p>