Skip to content
Open
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
8 changes: 8 additions & 0 deletions fire/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ def _google_section_permitted(line_info, state):
"""
if state.section.indentation is None: # We're not in a section yet.
return True
if state.section.format == Formats.NUMPY:
colon_index = line_info.remaining.find(':')
if colon_index > 0 and line_info.remaining[colon_index - 1].isspace():
# Numpy-style parameter lines have a space before the colon (e.g.
# "argument : int"), unlike Google section headers (e.g. "Args:"). Such
# a line is a parameter, not a new section, even if the parameter's name
# matches a section title (e.g. an argument named "argument").
return False
return (line_info.indentation <= state.section.indentation
or line_info.indentation < state.section.line1_indentation)

Expand Down
22 changes: 22 additions & 0 deletions fire/docstrings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ def test_numpy_format_multiline_arg_description(self):
)
self.assertEqual(expected_docstring_info, docstring_info)

def test_numpy_format_arg_name_matches_section_title(self):
docstring = """Run.

Parameters
----------
executable :
Executable to run
argument :
Positional argument to the executable
"""
docstring_info = docstrings.parse(docstring)
expected_docstring_info = DocstringInfo(
summary='Run.',
args=[
ArgInfo(name='executable', type='',
description='Executable to run'),
ArgInfo(name='argument', type='',
description='Positional argument to the executable'),
],
)
self.assertEqual(expected_docstring_info, docstring_info)

def test_multisection_docstring(self):
docstring = """Docstring summary.

Expand Down