diff options
| author | Georg Brandl <georg@python.org> | 2011-01-15 15:40:59 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2011-01-15 15:40:59 +0100 |
| commit | 0db5e3b6db3fc7732b963e5dd0068c7517b56353 (patch) | |
| tree | 3cf9d51e2ed1c848d54a460c455982bc0e18fece /sphinx/pycode | |
| parent | 93a45c27161bd8f7890f4bdca873ad49b7aaca91 (diff) | |
| download | sphinx-0db5e3b6db3fc7732b963e5dd0068c7517b56353.tar.gz | |
#431: Doc comments for attributes can now be given on the same line as the assignment.
Diffstat (limited to 'sphinx/pycode')
| -rw-r--r-- | sphinx/pycode/__init__.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index e4758835..e15e42bf 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -85,10 +85,30 @@ class AttrDocVisitor(nodes.NodeVisitor): self.in_init -= 1 def visit_expr_stmt(self, node): - """Visit an assignment which may have a special comment before it.""" + """Visit an assignment which may have a special comment before (or + after) it. + """ if _eq not in node.children: # not an assignment (we don't care for augmented assignments) return + # look *after* the node; there may be a comment prefixing the NEWLINE + # of the simple_stmt + parent = node.parent + idx = parent.children.index(node) + 1 + while idx < len(parent): + if parent[idx].type == sym.SEMI: + idx += 1 + continue # skip over semicolon + if parent[idx].type == sym.NEWLINE: + prefix = parent[idx].get_prefix() + if not isinstance(prefix, unicode): + prefix = prefix.decode(self.encoding) + docstring = prepare_commentdoc(prefix) + if docstring: + self.add_docstring(node, docstring) + return # don't allow docstrings both before and after + break + # now look *before* the node pnode = node[0] prefix = pnode.get_prefix() # if the assignment is the first statement on a new indentation |
