ext.napoleon: Do not consume colons within inline code

Fixes gh-7581
This commit is contained in:
Eric Wieser 2020-04-30 08:57:24 +01:00
parent 21ca43719a
commit 453fe55dc9
2 changed files with 33 additions and 9 deletions

View File

@ -30,7 +30,9 @@ _google_section_regex = re.compile(r'^(\s|\w)+:\s*$')
_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)')
_numpy_section_regex = re.compile(r'^[=\-`:\'"~^_*+#<>]{2,}\s*$')
_single_colon_regex = re.compile(r'(?<!:):(?!:)')
_xref_regex = re.compile(r'(:(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)')
_xref_or_code_regex = re.compile(
r'((?::(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)|'
r'(?:``.+``))')
_bullet_list_regex = re.compile(r'^(\*|\+|\-)(\s+\S|\s*$)')
_enumerated_list_regex = re.compile(
r'^(?P<paren>\()?'
@ -728,7 +730,7 @@ class GoogleDocstring:
after_colon = []
colon = ''
found_colon = False
for i, source in enumerate(_xref_regex.split(line)):
for i, source in enumerate(_xref_or_code_regex.split(line)):
if found_colon:
after_colon.append(source)
else:

View File

@ -78,15 +78,17 @@ class InlineAttributeTest(BaseDocstringTest):
def test_class_data_member(self):
config = Config()
docstring = """data member description:
docstring = dedent("""\
data member description:
- a: b
"""
""")
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = """data member description:
expected = dedent("""\
data member description:
- a: b"""
- a: b""")
self.assertEqual(expected, actual)
@ -95,10 +97,30 @@ class InlineAttributeTest(BaseDocstringTest):
docstring = """b: data member description with :ref:`reference`"""
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = """data member description with :ref:`reference`
expected = dedent("""\
data member description with :ref:`reference`
:type: b"""
:type: b""")
self.assertEqual(expected, actual)
def test_class_data_member_inline_no_type(self):
config = Config()
docstring = """data with ``a : in code`` and :ref:`reference` and no type"""
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = """data with ``a : in code`` and :ref:`reference` and no type"""
self.assertEqual(expected, actual)
def test_class_data_member_inline_ref_in_type(self):
config = Config()
docstring = """:class:`int`: data member description"""
actual = str(GoogleDocstring(docstring, config=config, app=None,
what='attribute', name='some_data', obj=0))
expected = dedent("""\
data member description
:type: :class:`int`""")
self.assertEqual(expected, actual)