diff --git a/fire/docstrings.py b/fire/docstrings.py index 1cfadea9..dd07bb0f 100644 --- a/fire/docstrings.py +++ b/fire/docstrings.py @@ -338,7 +338,8 @@ def _as_arg_name_and_type(text): tokens = text.split() if len(tokens) < 2: return None - if _is_arg_name(tokens[0]): + if _is_arg_name(tokens[0]) and not _is_arg_name(tokens[1]): + # if _is_arg_name(tokens[0]): type_token = ' '.join(tokens[1:]) type_token = type_token.lstrip('{([').rstrip('])}') return tokens[0], type_token @@ -406,7 +407,8 @@ def _consume_google_args_line(line_info, state): state.current_arg = arg else: if state.current_arg: - state.current_arg.description.lines.append(split_line[0]) + state.current_arg.description.lines.append(first + ':' + second) + # state.current_arg.description.lines.append(split_line[0]) else: if state.current_arg: state.current_arg.description.lines.append(split_line[0]) diff --git a/fire/docstrings_test.py b/fire/docstrings_test.py index 2328ef16..1a2f4901 100644 --- a/fire/docstrings_test.py +++ b/fire/docstrings_test.py @@ -170,6 +170,33 @@ def test_google_format_multiline_arg_description(self): ) self.assertEqual(expected_docstring_info, docstring_info) + def test_google_format_multiline_arg_description_with_colon(self): + docstring = """Docstring summary. + + This is a longer description of the docstring. It spans multiple lines, as + is allowed. + + Args: + param1 (int): The first parameter. + param2 (str): The second parameter. This has a lot of text, enough to + cover two lines. This description also contains a : colon. + """ + docstring_info = docstrings.parse(docstring) + expected_docstring_info = DocstringInfo( + summary='Docstring summary.', + description='This is a longer description of the docstring. It spans ' + 'multiple lines, as\nis allowed.', + args=[ + ArgInfo(name='param1', type='int', + description='The first parameter.'), + ArgInfo(name='param2', type='str', + description='The second parameter. This has a lot of text, ' + 'enough to cover two lines. This description ' + 'also contains a : colon.'), + ], + ) + self.assertEqual(expected_docstring_info, docstring_info) + def test_rst_format_typed_args_and_returns(self): docstring = """Docstring summary.