Black: When doc string contains tab, black formatting fails.

Created on 18 Sep 2020  路  3Comments  路  Source: psf/black

When running black on method which doc string has tab in the middle of the string, black says:

error: cannot format black_example.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. 

To Reproduce Steps to reproduce the behavior:

  1. Take this file, which has tab in between foobarand is words.
  2. Run black with command: black black_example.py
  3. See error
error: cannot format balck_example.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: C:\Users\user\AppData\Local\Temp\blk_gf63oczm.log

In the log file I see:

--- src
+++ dst
@@ -24,11 +24,11 @@
       body=
         Expr(
           value=
             Constant(
               value=
-                'Something\nfoobar\tis other',  # str
+                'Something\nfoobar      is other',  # str
             )  # /Constant
         )  # /Expr
         Pass(
         )  # /Pass
       decorator_list=

Expected behavior
Did expect black to format tab to spaces correctly.

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: Windows 10, Python 3.8.1

Does this bug also happen on master?
Yes, tried with the online formatter.

Additional context
This looks like a regression, because error is not displayed in the 19,x release.

bug duplicate

Most helpful comment

Thank you @hugovk, I also believe this is a duplicate of #1601. @aaltat perhaps +1 the original bug report?

All 3 comments

Thanks for the report, this looks like a duplicate of https://github.com/psf/black/issues/1601.

Looks pretty much related. Did not spot it when reporting this issue.

Thank you @hugovk, I also believe this is a duplicate of #1601. @aaltat perhaps +1 the original bug report?

Was this page helpful?
0 / 5 - 0 ratings