Skip to content

Fix crashes with mypaint codebase #138

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 9 additions & 2 deletions pyment/docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions tests/mypaint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def func1(param1):
"""
:param param1:
foo bar
"""
pass

def func2(param1):
"""
:param float param2; foo bar
"""
pass
21 changes: 21 additions & 0 deletions tests/mypaint.py.patch
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down