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

BUG: Fix returns parsing no name #429

Merged
merged 2 commits into from
Sep 17, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ def _parse_param_list(self, content, single_element_is_type=False):
params = []
while not r.eof():
header = r.read().strip()
if " :" in header:
arg_name, arg_type = header.split(" :", maxsplit=1)
arg_name, arg_type = arg_name.strip(), arg_type.strip()
if " : " in header:
arg_name, arg_type = header.split(" : ", maxsplit=1)
else:
# NOTE: param line with single element should never have a
# a " :" before the description line, so this should probably
# warn.
if header.endswith(" :"):
header = header[:-2]
if single_element_is_type:
arg_name, arg_type = "", header
else:
Expand Down
15 changes: 15 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,21 @@ def test_empty_first_line():
)


def test_returns_with_roles_no_names():
"""Make sure colons that are part of sphinx roles are not misinterpreted
as type separator in returns section. See gh-428."""
docstring = NumpyDocString(
"""
Returns
-------
str or :class:`NumpyDocString`
"""
)
expected = "str or :class:`NumpyDocString`" # not "str or : class:...
assert docstring["Returns"][0].type == expected
assert expected in str(docstring)


def test_trailing_colon():
assert doc8["Parameters"][0].name == "data"

Expand Down