Merge pull request #4157 from tk0miya/4156_parse_class_comment

Fix #4156: failed to parse class comment
This commit is contained in:
Takeshi KOMIYA 2017-10-21 13:45:33 +09:00 committed by GitHub
commit f224f3ca25
2 changed files with 13 additions and 0 deletions

View File

@ -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()

View File

@ -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'