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

Black removes leading and trailing spaces in multiline docstrings but fails to remove them from one-line docstrings #1738

Closed
MarkCBell opened this issue Oct 2, 2020 · 0 comments · Fixed by #1740
Labels
T: bug Something isn't working

Comments

@MarkCBell
Copy link
Contributor

With the file test.py containing

def foo(a):
    """ This is fine. """

    return a + 1


def bar(a):
    """As is this."""

    return a + 1


def baz(a):
    """ This is not.

    Since it uses more than one line. """

    return a + 1

Running black --diff test.py results in a diff of:

@@ -9,10 +9,10 @@
 
     return a + 1
 
 
 def baz(a):
-    """ This is not.
+    """This is not.
 
-    Since it uses more than one line. """
+    Since it uses more than one line."""
 
     return a + 1

Expected behavior

Black should also complain that the docstring of foo contains a leading / trailing space and remove these. Note that all one-line examples in PEP 257 https://www.python.org/dev/peps/pep-0257/#one-line-docstrings have no leading / trailing spaces.

Environment (please complete the following information):

  • Version: master
  • OS: Linux (Ubuntu 20.04)
  • Python Version: Python 3.8.2

Does this bug also happen on master?

This also happens on master.

@MarkCBell MarkCBell added the T: bug Something isn't working label Oct 2, 2020
JelleZijlstra pushed a commit that referenced this issue Apr 22, 2021
#1740)

Fixes #1738. Fixes #1812.

Previously, Black removed leading and trailing spaces in multiline docstrings but failed to remove them from one-line docstrings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant