Black: INTERNAL ERROR when formatting docstrings containing literal tab characters

Created on 27 Aug 2020  Â·  3Comments  Â·  Source: psf/black

To Reproduce

black-repro-tabs.py:

class C:
    """
    Words   With    Tabs
    """
    pass
(venv38) jreese@garbodor ~/scratch » black --diff --safe black-repro-tabs.py
error: cannot format black-repro-tabs.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: /var/folders/_b/6gpzshq548d4d_4bk1m5sq280000gn/T/blk_epxedyba.log
Oh no! 💥 💔 💥
1 file would fail to reformat.
(venv38) jreese@garbodor ~/scratch ‹123› » cat /var/folders/_b/6gpzshq548d4d_4bk1m5sq280000gn/T/blk_epxedyba.log
--- src
+++ dst
@@ -5,11 +5,11 @@
       body=
         Expr(
           value=
             Constant(
               value=
-                'Words\tWith\tTabs',  # str
+                'Words       With    Tabs',  # str
             )  # /Constant
         )  # /Expr
         Pass(
         )  # /Pass
       decorator_list=

Expected behavior

Should be formatted using consistent tab characters (or replaced with spaces? 🤷) on both passes.

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: Python 3.8.5 on Linux and

Does this bug also happen on master?**

Yes.

Additional context

@thatch says git bisect points to a4c11a75e12300abfbe4c36854e450d42bdd1ee7 where docstring formatting was introduced.

bug duplicate

Most helpful comment

This seems different to #1601 which was reported on 19.10b0 and from the discussion was specific to tabs at the end of a line.

I view that issue as for all "Black produced code that is not equivalent to the source" errors due to tabs in docstrings being replaced since the responsible commit (a4c11a75e12300abfbe4c36854e450d42bdd1ee7) and possible fix for all these cases is the same. Also the original bug with tabs at the end still exists as of version 20.08b1.

All 3 comments

Hello @jreese, this is a duplicate of #1601. Thanks for filing, perhaps +1 the original issue?

Duplicate with black 20.8b1 (wasn't immediately obvious to me it was failing within docstrings):

https://github.com/biopython/biopython/issues/3236

This seems different to #1601 which was reported on 19.10b0 and from the discussion was specific to tabs at the end of a line.

This seems different to #1601 which was reported on 19.10b0 and from the discussion was specific to tabs at the end of a line.

I view that issue as for all "Black produced code that is not equivalent to the source" errors due to tabs in docstrings being replaced since the responsible commit (a4c11a75e12300abfbe4c36854e450d42bdd1ee7) and possible fix for all these cases is the same. Also the original bug with tabs at the end still exists as of version 20.08b1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dimaqq picture dimaqq  Â·  3Comments

dgnsrekt picture dgnsrekt  Â·  3Comments

feluxe picture feluxe  Â·  3Comments

kissgyorgy picture kissgyorgy  Â·  3Comments

gyermolenko picture gyermolenko  Â·  3Comments