mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Closes #1831: [Napoleon] Makes google type regex greedy to consume entire type, even if it contains colons
This commit is contained in:
parent
80eb821ec8
commit
42f2b30579
@ -23,8 +23,8 @@ from sphinx.util.pycompat import UnicodeMixin
|
|||||||
|
|
||||||
|
|
||||||
_directive_regex = re.compile(r'\.\. \S+::')
|
_directive_regex = re.compile(r'\.\. \S+::')
|
||||||
_google_untyped_arg_regex = re.compile(r'\s*(.+?)\s*:\s*(.*)')
|
_google_untyped_arg_regex = re.compile(r'(.+)\s*(?<!:):(?!:)\s*(.*)')
|
||||||
_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.+?)\s*\)\s*:\s*(.*)')
|
_google_typed_arg_regex = re.compile(r'(.+)\((.+)\)\s*(?<!:):(?!:)\s*(.*)')
|
||||||
|
|
||||||
|
|
||||||
class GoogleDocstring(UnicodeMixin):
|
class GoogleDocstring(UnicodeMixin):
|
||||||
@ -207,15 +207,15 @@ class GoogleDocstring(UnicodeMixin):
|
|||||||
if parse_type:
|
if parse_type:
|
||||||
match = _google_typed_arg_regex.match(line)
|
match = _google_typed_arg_regex.match(line)
|
||||||
if match:
|
if match:
|
||||||
_name = match.group(1)
|
_name = match.group(1).strip()
|
||||||
_type = match.group(2)
|
_type = match.group(2).strip()
|
||||||
_desc = match.group(3)
|
_desc = match.group(3).strip()
|
||||||
|
|
||||||
if not match:
|
if not match:
|
||||||
match = _google_untyped_arg_regex.match(line)
|
match = _google_untyped_arg_regex.match(line)
|
||||||
if match:
|
if match:
|
||||||
_name = match.group(1)
|
_name = match.group(1).strip()
|
||||||
_desc = match.group(2)
|
_desc = match.group(2).strip()
|
||||||
|
|
||||||
if _name[:2] == '**':
|
if _name[:2] == '**':
|
||||||
_name = r'\*\*'+_name[2:]
|
_name = r'\*\*'+_name[2:]
|
||||||
@ -244,14 +244,14 @@ class GoogleDocstring(UnicodeMixin):
|
|||||||
_name, _type, _desc = '', '', lines
|
_name, _type, _desc = '', '', lines
|
||||||
match = _google_typed_arg_regex.match(lines[0])
|
match = _google_typed_arg_regex.match(lines[0])
|
||||||
if match:
|
if match:
|
||||||
_name = match.group(1)
|
_name = match.group(1).strip()
|
||||||
_type = match.group(2)
|
_type = match.group(2).strip()
|
||||||
_desc = match.group(3)
|
_desc = match.group(3).strip()
|
||||||
else:
|
else:
|
||||||
match = _google_untyped_arg_regex.match(lines[0])
|
match = _google_untyped_arg_regex.match(lines[0])
|
||||||
if match:
|
if match:
|
||||||
_type = match.group(1)
|
_type = match.group(1).strip()
|
||||||
_desc = match.group(2)
|
_desc = match.group(2).strip()
|
||||||
if match:
|
if match:
|
||||||
lines[0] = _desc
|
lines[0] = _desc
|
||||||
_desc = lines
|
_desc = lines
|
||||||
|
@ -344,6 +344,53 @@ Returns:
|
|||||||
actual = str(GoogleDocstring(docstring))
|
actual = str(GoogleDocstring(docstring))
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_colon_in_return_type(self):
|
||||||
|
docstring = """Example property.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:py:class:`~.module.submodule.SomeClass`: an example instance
|
||||||
|
if available, None if not available.
|
||||||
|
"""
|
||||||
|
expected = """Example property.
|
||||||
|
|
||||||
|
:returns: an example instance
|
||||||
|
if available, None if not available.
|
||||||
|
:rtype: :py:class:`~.module.submodule.SomeClass`
|
||||||
|
"""
|
||||||
|
actual = str(GoogleDocstring(docstring))
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_kwargs_in_arguments(self):
|
||||||
|
docstring = """Allows to create attributes binded to this device.
|
||||||
|
|
||||||
|
Some other paragraph.
|
||||||
|
|
||||||
|
Code sample for usage::
|
||||||
|
|
||||||
|
dev.bind(loopback=Loopback)
|
||||||
|
dev.loopback.configure()
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
**kwargs: name/class pairs that will create resource-managers
|
||||||
|
bound as instance attributes to this instance. See code
|
||||||
|
example above.
|
||||||
|
"""
|
||||||
|
expected = """Allows to create attributes binded to this device.
|
||||||
|
|
||||||
|
Some other paragraph.
|
||||||
|
|
||||||
|
Code sample for usage::
|
||||||
|
|
||||||
|
dev.bind(loopback=Loopback)
|
||||||
|
dev.loopback.configure()
|
||||||
|
|
||||||
|
:param \\*\\*kwargs: name/class pairs that will create resource-managers
|
||||||
|
bound as instance attributes to this instance. See code
|
||||||
|
example above.
|
||||||
|
"""
|
||||||
|
actual = str(GoogleDocstring(docstring))
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
|
||||||
class NumpyDocstringTest(BaseDocstringTest):
|
class NumpyDocstringTest(BaseDocstringTest):
|
||||||
docstrings = [(
|
docstrings = [(
|
||||||
|
Loading…
Reference in New Issue
Block a user