From e968a6c1a1041f082a0c4c8b6fae727c68dd525e Mon Sep 17 00:00:00 2001 From: Rob Ruana Date: Sun, 15 Feb 2015 18:51:29 -0500 Subject: [PATCH] Fix Google Docstring argument regex in Napoleon. Argument type matching is now more permissive --- sphinx/ext/napoleon/docstring.py | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 146ea66ae..fa3c65bf5 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -23,9 +23,8 @@ from sphinx.util.pycompat import UnicodeMixin _directive_regex = re.compile(r'\.\. \S+::') -_google_untyped_arg_regex = re.compile(r'\s*(\*?\*?\w+)\s*:\s*(.*)') -_google_typed_arg_regex = re.compile(r'\s*(\*?\*?\w+)\s*\(\s*(.+?)\s*\)\s*:' - r'\s*(.*)') +_google_untyped_arg_regex = re.compile(r'\s*(.+?)\s*:\s*(.*)') +_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.+?)\s*\)\s*:\s*(.*)') class GoogleDocstring(UnicodeMixin): @@ -178,17 +177,17 @@ class GoogleDocstring(UnicodeMixin): def _consume_indented_block(self, indent=1): lines = [] line = self._line_iter.peek() - while(not self._is_section_break() - and (not line or self._is_indented(line, indent))): + while(not self._is_section_break() and + (not line or self._is_indented(line, indent))): lines.append(next(self._line_iter)) line = self._line_iter.peek() return lines def _consume_contiguous(self): lines = [] - while (self._line_iter.has_next() - and self._line_iter.peek() - and not self._is_section_header()): + while (self._line_iter.has_next() and + self._line_iter.peek() and + not self._is_section_header()): lines.append(next(self._line_iter)) return lines @@ -400,11 +399,11 @@ class GoogleDocstring(UnicodeMixin): def _is_section_break(self): line = self._line_iter.peek() - return (not self._line_iter.has_next() - or self._is_section_header() - or (self._is_in_section - and line - and not self._is_indented(line, self._section_indent))) + return (not self._line_iter.has_next() or + self._is_section_header() or + (self._is_in_section and + line and + not self._is_indented(line, self._section_indent))) def _parse(self): self._parsed_lines = self._consume_empty() @@ -743,12 +742,12 @@ class NumpyDocstring(GoogleDocstring): def _is_section_break(self): line1, line2 = self._line_iter.peek(2) - return (not self._line_iter.has_next() - or self._is_section_header() - or ['', ''] == [line1, line2] - or (self._is_in_section - and line1 - and not self._is_indented(line1, self._section_indent))) + return (not self._line_iter.has_next() or + self._is_section_header() or + ['', ''] == [line1, line2] or + (self._is_in_section and + line1 and + not self._is_indented(line1, self._section_indent))) def _is_section_header(self): section, underline = self._line_iter.peek(2)