diff --git a/pyment/docstring.py b/pyment/docstring.py index 2361137..67fbd60 100644 --- a/pyment/docstring.py +++ b/pyment/docstring.py @@ -987,6 +987,7 @@ def _extra_tagstyle_elements(self, data): param_part, param_description = line.split(':', 1) else: print("WARNING: malformed docstring parameter") + continue res = re.split(r'\s+', param_part.strip()) if len(res) == 1: param_name = res[0].strip() @@ -1032,9 +1033,15 @@ def _extra_tagstyle_elements(self, data): else: # suppose to be line of a multiline element if last_element['nature'] == 'param': - ret[last_element['name']]['description'] += f"\n{line}" + if ret[last_element['name']]['description'] is None: + ret[last_element['name']]['description'] = line + else: + ret[last_element['name']]['description'] += f"\n{line}" elif last_element['nature'] == 'type': - ret[last_element['name']]['description'] += f"\n{line}" + if ret[last_element['name']]['description'] is None: + ret[last_element['name']]['description'] = line + else: + ret[last_element['name']]['description'] += f"\n{line}" return ret def _extract_not_tagstyle_old_way(self, data): diff --git a/tests/mypaint.py b/tests/mypaint.py new file mode 100644 index 0000000..867aa0c --- /dev/null +++ b/tests/mypaint.py @@ -0,0 +1,12 @@ +def func1(param1): + """ + :param param1: + foo bar + """ + pass + +def func2(param1): + """ + :param float param2; foo bar + """ + pass diff --git a/tests/mypaint.py.patch b/tests/mypaint.py.patch new file mode 100644 index 0000000..2fa3135 --- /dev/null +++ b/tests/mypaint.py.patch @@ -0,0 +1,21 @@ +--- a/mypaint.py ++++ b/mypaint.py +@@ -1,12 +1,15 @@ + def func1(param1): + """ +- :param param1: +- foo bar ++ ++ :param param1: foo bar ++ + """ + pass + + def func2(param1): + """ +- :param float param2; foo bar ++ ++ :param param1: ++ + """ + pass diff --git a/tests/test_issues.py b/tests/test_issues.py index 0e85d20..d20899e 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -307,6 +307,15 @@ def testIssue99(self): f.close() self.assertEqual(''.join(p.diff()), patch) + def testMypaint(self): + # Title: Crash when multiline description starts on next line + p = pym.PyComment(absdir('mypaint.py')) + p._parse() + f = open(absdir('mypaint.py.patch')) + patch = f.read() + f.close() + self.assertEqual(''.join(p.diff()), patch) + def main(): unittest.main()