mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4996 from tk0miya/4914_dataclasses
Fix #4914: autodoc: Parsing error when using dataclasses without default values
This commit is contained in:
commit
1b5bc55956
1
CHANGES
1
CHANGES
@ -39,6 +39,7 @@ Bugs fixed
|
|||||||
* #4973: latex: glossary directive adds whitespace to each item
|
* #4973: latex: glossary directive adds whitespace to each item
|
||||||
* #4980: latex: Explicit labels on code blocks are duplicated
|
* #4980: latex: Explicit labels on code blocks are duplicated
|
||||||
* #4919: node.asdom() crashes if toctree has :numbered: option
|
* #4919: node.asdom() crashes if toctree has :numbered: option
|
||||||
|
* #4914: autodoc: Parsing error when using dataclasses without default values
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -224,11 +224,12 @@ class AfterCommentParser(TokenProcessor):
|
|||||||
def parse(self):
|
def parse(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""Parse the code and obtain comment after assignment."""
|
"""Parse the code and obtain comment after assignment."""
|
||||||
# skip lvalue (until '=' operator)
|
# skip lvalue (or whole of AnnAssign)
|
||||||
while self.fetch_token() != [OP, '=']:
|
while not self.fetch_token().match([OP, '='], NEWLINE, COMMENT):
|
||||||
assert self.current
|
assert self.current
|
||||||
|
|
||||||
# skip rvalue
|
# skip rvalue (if exists)
|
||||||
|
if self.current == [OP, '=']:
|
||||||
self.fetch_rvalue()
|
self.fetch_rvalue()
|
||||||
|
|
||||||
if self.current == COMMENT:
|
if self.current == COMMENT:
|
||||||
|
@ -100,11 +100,13 @@ def test_comment_picker_location():
|
|||||||
def test_annotated_assignment_py36():
|
def test_annotated_assignment_py36():
|
||||||
source = ('a: str = "Sphinx" #: comment\n'
|
source = ('a: str = "Sphinx" #: comment\n'
|
||||||
'b: int = 1\n'
|
'b: int = 1\n'
|
||||||
'"""string on next line"""')
|
'"""string on next line"""\n'
|
||||||
|
'c: int #: comment')
|
||||||
parser = Parser(source)
|
parser = Parser(source)
|
||||||
parser.parse()
|
parser.parse()
|
||||||
assert parser.comments == {('', 'a'): 'comment',
|
assert parser.comments == {('', 'a'): 'comment',
|
||||||
('', 'b'): 'string on next line'}
|
('', 'b'): 'string on next line',
|
||||||
|
('', 'c'): 'comment'}
|
||||||
assert parser.definitions == {}
|
assert parser.definitions == {}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user