mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix ValueError popping out in sphinx.ext.napoleon
(#10709)
There's some parts of the code still expecting a StopIteration instead.
This commit is contained in:
parent
9845500ffa
commit
0555345ad7
@ -46,7 +46,11 @@ _SINGLETONS = ("None", "True", "False", "Ellipsis")
|
|||||||
|
|
||||||
|
|
||||||
class Deque(collections.deque):
|
class Deque(collections.deque):
|
||||||
"""A subclass of deque with an additional `.Deque.get` method."""
|
"""
|
||||||
|
A subclass of deque that mimics ``pockets.iterators.modify_iter``.
|
||||||
|
|
||||||
|
The `.Deque.get` and `.Deque.next` methods are added.
|
||||||
|
"""
|
||||||
|
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
|
|
||||||
@ -57,6 +61,12 @@ class Deque(collections.deque):
|
|||||||
"""
|
"""
|
||||||
return self[n] if n < len(self) else self.sentinel
|
return self[n] if n < len(self) else self.sentinel
|
||||||
|
|
||||||
|
def next(self) -> Any:
|
||||||
|
if self:
|
||||||
|
return super().popleft()
|
||||||
|
else:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
def _convert_type_spec(_type: str, translations: Dict[str, str] = {}) -> str:
|
def _convert_type_spec(_type: str, translations: Dict[str, str] = {}) -> str:
|
||||||
"""Convert type specification to reference in reST."""
|
"""Convert type specification to reference in reST."""
|
||||||
@ -240,7 +250,7 @@ class GoogleDocstring:
|
|||||||
line = self._lines.get(0)
|
line = self._lines.get(0)
|
||||||
while(not self._is_section_break() and
|
while(not self._is_section_break() and
|
||||||
(not line or self._is_indented(line, indent))):
|
(not line or self._is_indented(line, indent))):
|
||||||
lines.append(self._lines.popleft())
|
lines.append(self._lines.next())
|
||||||
line = self._lines.get(0)
|
line = self._lines.get(0)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@ -249,20 +259,20 @@ class GoogleDocstring:
|
|||||||
while (self._lines and
|
while (self._lines and
|
||||||
self._lines.get(0) and
|
self._lines.get(0) and
|
||||||
not self._is_section_header()):
|
not self._is_section_header()):
|
||||||
lines.append(self._lines.popleft())
|
lines.append(self._lines.next())
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def _consume_empty(self) -> List[str]:
|
def _consume_empty(self) -> List[str]:
|
||||||
lines = []
|
lines = []
|
||||||
line = self._lines.get(0)
|
line = self._lines.get(0)
|
||||||
while self._lines and not line:
|
while self._lines and not line:
|
||||||
lines.append(self._lines.popleft())
|
lines.append(self._lines.next())
|
||||||
line = self._lines.get(0)
|
line = self._lines.get(0)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def _consume_field(self, parse_type: bool = True, prefer_type: bool = False
|
def _consume_field(self, parse_type: bool = True, prefer_type: bool = False
|
||||||
) -> Tuple[str, str, List[str]]:
|
) -> Tuple[str, str, List[str]]:
|
||||||
line = self._lines.popleft()
|
line = self._lines.next()
|
||||||
|
|
||||||
before, colon, after = self._partition_field_on_colon(line)
|
before, colon, after = self._partition_field_on_colon(line)
|
||||||
_name, _type, _desc = before, '', after
|
_name, _type, _desc = before, '', after
|
||||||
@ -300,7 +310,7 @@ class GoogleDocstring:
|
|||||||
return fields
|
return fields
|
||||||
|
|
||||||
def _consume_inline_attribute(self) -> Tuple[str, List[str]]:
|
def _consume_inline_attribute(self) -> Tuple[str, List[str]]:
|
||||||
line = self._lines.popleft()
|
line = self._lines.next()
|
||||||
_type, colon, _desc = self._partition_field_on_colon(line)
|
_type, colon, _desc = self._partition_field_on_colon(line)
|
||||||
if not colon or not _desc:
|
if not colon or not _desc:
|
||||||
_type, _desc = _desc, _type
|
_type, _desc = _desc, _type
|
||||||
@ -338,7 +348,7 @@ class GoogleDocstring:
|
|||||||
return lines
|
return lines
|
||||||
|
|
||||||
def _consume_section_header(self) -> str:
|
def _consume_section_header(self) -> str:
|
||||||
section = self._lines.popleft()
|
section = self._lines.next()
|
||||||
stripped_section = section.strip(':')
|
stripped_section = section.strip(':')
|
||||||
if stripped_section.lower() in self._sections:
|
if stripped_section.lower() in self._sections:
|
||||||
section = stripped_section
|
section = stripped_section
|
||||||
@ -347,14 +357,14 @@ class GoogleDocstring:
|
|||||||
def _consume_to_end(self) -> List[str]:
|
def _consume_to_end(self) -> List[str]:
|
||||||
lines = []
|
lines = []
|
||||||
while self._lines:
|
while self._lines:
|
||||||
lines.append(self._lines.popleft())
|
lines.append(self._lines.next())
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def _consume_to_next_section(self) -> List[str]:
|
def _consume_to_next_section(self) -> List[str]:
|
||||||
self._consume_empty()
|
self._consume_empty()
|
||||||
lines = []
|
lines = []
|
||||||
while not self._is_section_break():
|
while not self._is_section_break():
|
||||||
lines.append(self._lines.popleft())
|
lines.append(self._lines.next())
|
||||||
return lines + self._consume_empty()
|
return lines + self._consume_empty()
|
||||||
|
|
||||||
def _dedent(self, lines: List[str], full: bool = False) -> List[str]:
|
def _dedent(self, lines: List[str], full: bool = False) -> List[str]:
|
||||||
@ -1170,7 +1180,7 @@ class NumpyDocstring(GoogleDocstring):
|
|||||||
|
|
||||||
def _consume_field(self, parse_type: bool = True, prefer_type: bool = False
|
def _consume_field(self, parse_type: bool = True, prefer_type: bool = False
|
||||||
) -> Tuple[str, str, List[str]]:
|
) -> Tuple[str, str, List[str]]:
|
||||||
line = self._lines.popleft()
|
line = self._lines.next()
|
||||||
if parse_type:
|
if parse_type:
|
||||||
_name, _, _type = self._partition_field_on_colon(line)
|
_name, _, _type = self._partition_field_on_colon(line)
|
||||||
else:
|
else:
|
||||||
@ -1201,10 +1211,10 @@ class NumpyDocstring(GoogleDocstring):
|
|||||||
return self._consume_fields(prefer_type=True)
|
return self._consume_fields(prefer_type=True)
|
||||||
|
|
||||||
def _consume_section_header(self) -> str:
|
def _consume_section_header(self) -> str:
|
||||||
section = self._lines.popleft()
|
section = self._lines.next()
|
||||||
if not _directive_regex.match(section):
|
if not _directive_regex.match(section):
|
||||||
# Consume the header underline
|
# Consume the header underline
|
||||||
self._lines.popleft()
|
self._lines.next()
|
||||||
return section
|
return section
|
||||||
|
|
||||||
def _is_section_break(self) -> bool:
|
def _is_section_break(self) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user