0

When documenting instance variables, I can do

class Foo:
    def __init__(self):
        self.spam = 4
        """Docstring for instance attribute spam."""

This doesn't work for parallel assignment

class Foo:
    def __init__(self):
        self.spam, self.bar, self.moo = 4, 5, 6
        """Docstring for instance attribute spam."""

How can I document variables in parallel assignment?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
XrXr
  • 2,027
  • 1
  • 14
  • 20
  • Neither one of those does anything at all. You just have random string literals in your method; they are not docstrings. If you want comments, use comments. – kindall Jun 01 '14 at 16:27
  • These are for sphinx. It will look over these and generate doc for me. – XrXr Jun 01 '14 at 16:29
  • sphinx seems very broken to me, then. in any case, if sphinx doesn't let you write docstrings for parallel assignments... maybe don't do parallel assignments? – kindall Jun 01 '14 at 16:31

2 Answers2

0

autoattribute is for a single attribute. Here is a way to do it, together with autoclass or automodule:

class Foo:
    """
    :ivar spam: Description of spam
    :ivar bar: Description of bar
    :ivar moo: Description of moo
    """

    def __init__(self):
        self.spam, self.bar, self.moo = 4, 5, 6

The output looks a bit different compared to what you get with autoattribute, but I quite like it.

mzjn
  • 48,958
  • 13
  • 128
  • 248
0

I found that I can use Sephix markup inside the __init__ doc string block and make it look almost the same as using autoattribute.

class Foo:
    def __init__(self):
        """
        Something something

        .. py:attribute:: spam

           Something about spam

        .. py:attribute:: bar

           Something about br

        .. py:attribute:: moo

           Something about moo
        """
        self.spam, self.bar, self.moo = 4, 5, 6

This will look like http://xrxr.github.io/RapidPygame/levelmgr.html (interpreted and draw_list is done using this technique.) if autoclass_content is set to 'both' (If you pay attention, they are not in their right alphabetical place)

This works, but I still wonder if there is a better way.

XrXr
  • 2,027
  • 1
  • 14
  • 20