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

Trailing whitespace not preserved in docstring #1462

Closed
chebee7i opened this issue May 26, 2020 · 6 comments
Closed

Trailing whitespace not preserved in docstring #1462

chebee7i opened this issue May 26, 2020 · 6 comments
Labels
T: bug Something isn't working

Comments

@chebee7i
Copy link

chebee7i commented May 26, 2020

Describe the bug Trailing whitespace in docstrings is not preserved.

To Reproduce Steps to reproduce the behavior:

$ cat -E demo.py
def func():$
    """$
    Line with trailing whitespace    $
$
    Another line with trailing whitespace    $
$
    Done.$
    """$
    pass$

$ black demo.py
error: cannot format demo.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_geo3qids.log
Oh no! 💥 💔 💥
1 file failed to reformat.

$ cat /tmp/blk_geo3qids.log
--- src
+++ dst
@@ -16,11 +16,11 @@
       body=
         Expr(
           value=
             Constant(
               value=
-                'Line with trailing whitespace    \n\n Another line with trailing whitespace    \n\n Done.',  # str
+                'Line with trailing whitespace\n\n Another line with trailing whitespace\n\n Done.',  # str
             )  # /Constant
         )  # /Expr
         Pass(
         )  # /Pass
       decorator_list=

Expected behavior Trailing whitespace should be preserved or black should not complain.

Environment (please complete the following information):

  • Version: 9171535 (HEAD of master as of today)
  • OS and Python version: [e.g. Linux/Python 3.7.6]

Does this bug also happen on master?

It does happen on master. However, it does not happen at https://black.now.sh/?version=master. I'm not sure if that editor might be deleting the trailing whitespace?

@chebee7i chebee7i added the T: bug Something isn't working label May 26, 2020
@JelleZijlstra
Copy link
Collaborator

#1417 fixed a very similar crash, are you sure you are running on current master?

@chebee7i
Copy link
Author

Pretty sure. Just reconfirmed again on the new HEAD of master.

$ cat -E demo.py
def func():$
    """$
    Line with trailing whitespace    $
$
    Another line with trailing whitespace    $
$
    Done.$
    """$
    pass$

$ python -c "import black; print(black.__version__)"
19.10b1.dev1+g3461338

$ git log -n 1 HEAD
commit 34613383abad9afa5cc1b3945e50bbfca13d036e (HEAD -> master, upstream/master, upstream/HEAD)
Author: Richard Si <63936253+ichard26@users.noreply.github.com>
Date:   Tue May 26 22:42:07 2020 -0400

    Make 'python -m black' work (#1460)

$ python -m black demo.py
error: cannot format demo.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_c_1s9bnx.log
Oh no! 💥 💔 💥
1 file failed to reformat.

$ cat /tmp/blk_c_1s9bnx.log
--- src
+++ dst
@@ -16,11 +16,11 @@
       body=
         Expr(
           value=
             Constant(
               value=
-                'Line with trailing whitespace    \n\n Another line with trailing whitespace    \n\n Done.',  # str
+                'Line with trailing whitespace\n\n Another line with trailing whitespace\n\n Done.',  # str
             )  # /Constant
         )  # /Expr
         Pass(
         )  # /Pass
       decorator_list=

@chebee7i
Copy link
Author

chebee7i commented Jun 3, 2020

This is a regression from 19.3b0. Is it possible to get a quick fix out for this? I originally upgraded while trying to get around #875, but I had to revert due to the above issues. If more complicated to fix, no prob.

@Jackenmen
Copy link
Contributor

You did not say this happens on 19.10b0 in issue description 🤔

@chebee7i
Copy link
Author

chebee7i commented Jun 4, 2020

Actually, this does not seem to be happening on 19.10b0. My apologies!

@ichard26
Copy link
Collaborator

This also doesn't happen on 20.08b1 and therefore I will close this issue now.

(black-rHKUX7ap) R:\Programming\black>black temp.py --diff --color
--- temp.py     2020-08-30 16:41:16.245384 +0000
+++ temp.py     2020-08-30 16:41:33.472229 +0000
@@ -1,9 +1,9 @@
 def func():
     """
-    Line with trailing whitespace
+    Line with trailing whitespace

-    Another line with trailing whitespace
+    Another line with trailing whitespace

     Done.
     """
     pass
would reformat temp.py
All done! ✨ 🍰 ✨
1 file would be reformatted.

Environment:

  • Black version: Black 20.08b1
  • Python version: CPython 3.8.1
  • OS version: Windows 10 Home Edition Build 18363

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

No branches or pull requests

4 participants