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

Doc formatter reformats correct docstring #79

Closed
probicheaux opened this issue Oct 1, 2021 · 2 comments · Fixed by #179
Closed

Doc formatter reformats correct docstring #79

probicheaux opened this issue Oct 1, 2021 · 2 comments · Fixed by #179
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: enhancement Feature that is outside the scope of PEP 257
Milestone

Comments

@probicheaux
Copy link

with docformatter 1.4, command docformatter --wrap-summaries 100 --wrap-descriptions 100
the following docstring

"""hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet -v
"""

gets transformed to

"""hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet
-v."""

which is fine (correct), but then if I run docformatter again, the correct string incorrectly becomes

"""hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet.

-v.
"""
@probicheaux
Copy link
Author

probicheaux commented Oct 2, 2021

Proposing this patch, which supposes that parameter lists in the description usually should have a one line description preceding them

diff --git a/docformatter.py b/docformatter.py
index 07213e7..0927ce0 100755
--- a/docformatter.py
+++ b/docformatter.py
@@ -296,9 +296,10 @@ def split_summary_and_description(contents):
         if not split_lines[index].strip():
             # Empty line separation would indicate the rest is the description.
             found = True
-        elif is_probably_beginning_of_sentence(split_lines[index]):
+        if index + 1 < len(split_lines):
             # Symbol on second line probably is a description with a list.
-            found = True
+            if is_probably_beginning_of_sentence(split_lines[index+1]):
+                found = True

         if found:
             return ('\n'.join(split_lines[:index]).strip(),
diff --git a/test_docformatter.py b/test_docformatter.py
index 0908135..0537ce8 100755
--- a/test_docformatter.py
+++ b/test_docformatter.py
@@ -426,6 +426,13 @@ Hello.
             docstring,
             docformatter.format_docstring('    ', docstring))

+    def test_format_docstring_leave_multilines_summaries_with_symbols_alone(self):
+        docstring = '''"""hello yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet
+    -v."""'''
+        self.assertEqual(
+            docstring,
+            docformatter.format_docstring('    ', docstring))
+
     def test_format_code(self):
         self.assertEqual(
             '''\
@@ -957,7 +964,7 @@ def foo():\r
                              'This is the first\nWashington'))

     def test_split_summary_and_description_with_list_on_other_line(self):
-        self.assertEqual(('Test\n    test', '    @blah'),
+        self.assertEqual(('Test', '    test\n    @blah'),
                          docformatter.split_summary_and_description('''\
     Test
     test

@weibullguy
Copy link
Member

@probicheaux could you open a pull request with your proposed solution?

@weibullguy weibullguy added P: enhancement Feature that is outside the scope of PEP 257 C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) labels Aug 8, 2022
@weibullguy weibullguy added this to the v2.0.0 milestone Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: enhancement Feature that is outside the scope of PEP 257
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants