Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -22,6 +22,9 @@ Bugs fixed
- sphinx.application.CONFIG_FILENAME
- :confval:`viewcode_import`

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

Testing
--------

Expand Down
8 changes: 4 additions & 4 deletions sphinx/ext/napoleon/docstring.py
Expand Up @@ -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)

def __init__(self, docstring, config=None, app=None, what='', name='',
Expand Down Expand Up @@ -700,9 +700,9 @@ def _parse_raises_section(self, section):
fields = self._consume_fields(parse_type=False, prefer_type=True)
lines = [] # type: List[str]
for _name, _type, _desc in fields:
m = self._name_rgx.match(_type).groupdict()
if m['role']:
_type = m['name']
m = self._name_rgx.match(_type)
if m and m.group('name'):
_type = m.group('name')
_type = ' ' + _type if _type else ''
_desc = self._strip_empty(_desc)
_descs = ' ' + '\n '.join(_desc) if any(_desc) else ''
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ext_napoleon_docstring.py
Expand Up @@ -473,12 +473,21 @@ def test_raises_types(self):
A setting wasn't specified, or was invalid.
ValueError:
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

:raises RuntimeError: A setting wasn't specified, or was invalid.
: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.
"""),
################################
("""
Expand Down