diff options
-rw-r--r-- | sphinx/pycode/parser.py | 1 | ||||
-rw-r--r-- | tests/test_pycode_parser.py | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index 28da09c78..f9644c38e 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -343,6 +343,7 @@ class VariableCommentPicker(ast.NodeVisitor): self.current_classes.append(node.name) self.add_entry(node.name) self.context.append(node.name) + self.previous = node for child in node.body: self.visit(child) self.context.pop() diff --git a/tests/test_pycode_parser.py b/tests/test_pycode_parser.py index d794376fa..b9327999b 100644 --- a/tests/test_pycode_parser.py +++ b/tests/test_pycode_parser.py @@ -246,6 +246,18 @@ def test_nested_class(): 'Foo.Bar.attr2': 3} +def test_class_comment(): + source = ('import logging\n' + 'logger = logging.getLogger(__name__)\n' + '\n' + 'class Foo(object):\n' + ' """Bar"""\n') + parser = Parser(source) + parser.parse() + assert parser.comments == {} + assert parser.definitions == {'Foo': ('class', 4, 5)} + + def test_comment_picker_multiline_string(): source = ('class Foo(object):\n' ' a = None\n' |