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

Docstring description multiline parsing #476

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Next Next commit
quick fix
  • Loading branch information
thebadcoder96 committed Dec 21, 2023
commit 45e3a0e7be335b33fd83b24b06ba8fdc1baee884
13 changes: 9 additions & 4 deletions fire/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def parse(docstring):

args.extend([KwargInfo(
name=arg.name, type=_cast_to_known_type(_join_lines(arg.type.lines)),
description=_join_lines(arg.description.lines)) for arg in state.kwargs])
description=_join_lines(arg.description.lines, 'description')) for arg in state.kwargs])

return DocstringInfo(
summary=summary,
Expand Down Expand Up @@ -239,7 +239,7 @@ def _is_blank(line):
return not line or line.isspace()


def _join_lines(lines):
def _join_lines(lines, type=None):
"""Joins lines with the appropriate connective whitespace.

This puts a single space between consecutive lines, unless there's a blank
Expand All @@ -253,7 +253,7 @@ def _join_lines(lines):
# TODO(dbieber): Add parameters for variations in whitespace handling.
if not lines:
return None

started = False
group_texts = [] # Full text of each section.
group_lines = [] # Lines within the current section.
Expand All @@ -269,7 +269,12 @@ def _join_lines(lines):
group_lines = []

if group_lines: # Process the final group.
group_text = ' '.join(group_lines)
# group_text = ' '.join(group_lines)
if type == 'description':
group_text = '\n'.join(group_lines)
else:
group_text = ' '.join(group_lines)

group_texts.append(group_text)

return '\n\n'.join(group_texts)
Expand Down