Fix #4914: autodoc: Parsing error when using dataclasses without default values

This commit is contained in:
Takeshi KOMIYA 2018-05-21 00:24:15 +09:00
parent 679002c483
commit be8e2be47b
3 changed files with 10 additions and 6 deletions

View File

@ -33,6 +33,7 @@ Bugs fixed
* #4978: latex: shorthandoff is not set up for Brazil locale
* #4928: i18n: Ignore dot-directories like .git/ in LC_MESSAGES/
* #4946: py domain: type field could not handle "None" as a type
* #4914: autodoc: Parsing error when using dataclasses without default values
Testing
--------

View File

@ -224,11 +224,12 @@ class AfterCommentParser(TokenProcessor):
def parse(self):
# type: () -> None
"""Parse the code and obtain comment after assignment."""
# skip lvalue (until '=' operator)
while self.fetch_token() != [OP, '=']:
# skip lvalue (or whole of AnnAssign)
while not self.fetch_token().match([OP, '='], NEWLINE, COMMENT):
assert self.current
# skip rvalue
# skip rvalue (if exists)
if self.current == [OP, '=']:
self.fetch_rvalue()
if self.current == COMMENT:

View File

@ -100,11 +100,13 @@ def test_comment_picker_location():
def test_annotated_assignment_py36():
source = ('a: str = "Sphinx" #: comment\n'
'b: int = 1\n'
'"""string on next line"""')
'"""string on next line"""\n'
'c: int #: comment')
parser = Parser(source)
parser.parse()
assert parser.comments == {('', 'a'): 'comment',
('', 'b'): 'string on next line'}
('', 'b'): 'string on next line',
('', 'c'): 'comment'}
assert parser.definitions == {}