summaryrefslogtreecommitdiff
path: root/sphinx/pycode/parser.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-05-21 00:24:15 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-05-21 00:25:11 +0900
commitbe8e2be47b405723e39ff46e473829bcc8d17cb9 (patch)
tree00e122bd69e09a5809e3ecc494ebe431f2e6b1da /sphinx/pycode/parser.py
parent679002c483958a041772bd2a1f1014bb9dada9a8 (diff)
downloadsphinx-git-be8e2be47b405723e39ff46e473829bcc8d17cb9.tar.gz
Fix #4914: autodoc: Parsing error when using dataclasses without default values
Diffstat (limited to 'sphinx/pycode/parser.py')
-rw-r--r--sphinx/pycode/parser.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index deba48b1c..5c4291d3d 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -224,12 +224,13 @@ 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
- self.fetch_rvalue()
+ # skip rvalue (if exists)
+ if self.current == [OP, '=']:
+ self.fetch_rvalue()
if self.current == COMMENT:
self.comment = self.current.value