Fix #6220, #6225: napoleon: AttributeError is raised for raised section having references

This commit is contained in:
Takeshi KOMIYA 2019-03-31 22:15:06 +09:00
parent cbefc01b73
commit 8e356c3bf4
3 changed files with 16 additions and 4 deletions

View File

@ -22,6 +22,9 @@ Bugs fixed
- sphinx.application.CONFIG_FILENAME - sphinx.application.CONFIG_FILENAME
- :confval:`viewcode_import` - :confval:`viewcode_import`
* #6220, #6225: napoleon: AttributeError is raised for raised section having
references
Testing Testing
-------- --------

View File

@ -100,7 +100,7 @@ class GoogleDocstring:
""" """
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):`(?P<name>[a-zA-Z0-9_.-]+)`|" _name_rgx = re.compile(r"^\s*((?::(?P<role>\S+):)?`(?P<name>[a-zA-Z0-9_.-]+)`|"
r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X) r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X)
def __init__(self, docstring, config=None, app=None, what='', name='', def __init__(self, docstring, config=None, app=None, what='', name='',
@ -700,9 +700,9 @@ class GoogleDocstring:
fields = self._consume_fields(parse_type=False, prefer_type=True) fields = self._consume_fields(parse_type=False, prefer_type=True)
lines = [] # type: List[str] lines = [] # type: List[str]
for _name, _type, _desc in fields: for _name, _type, _desc in fields:
m = self._name_rgx.match(_type).groupdict() m = self._name_rgx.match(_type)
if m['role']: if m and m.group('name'):
_type = m['name'] _type = m.group('name')
_type = ' ' + _type if _type else '' _type = ' ' + _type if _type else ''
_desc = self._strip_empty(_desc) _desc = self._strip_empty(_desc)
_descs = ' ' + '\n '.join(_desc) if any(_desc) else '' _descs = ' ' + '\n '.join(_desc) if any(_desc) else ''

View File

@ -473,12 +473,21 @@ Raises:
A setting wasn't specified, or was invalid. A setting wasn't specified, or was invalid.
ValueError: ValueError:
Something something value error. Something something value error.
:py:class:`AttributeError`
errors for missing attributes.
~InvalidDimensionsError
If the dimensions couldn't be parsed.
`InvalidArgumentsError`
If the arguments are invalid.
""", """ """, """
Example Function Example Function
:raises RuntimeError: A setting wasn't specified, or was invalid. :raises RuntimeError: A setting wasn't specified, or was invalid.
:raises ValueError: Something something value error. :raises ValueError: Something something value error.
:raises AttributeError: errors for missing attributes.
:raises ~InvalidDimensionsError: If the dimensions couldn't be parsed.
:raises InvalidArgumentsError: If the arguments are invalid.
"""), """),
################################ ################################
(""" ("""