black icon indicating copy to clipboard operation
black copied to clipboard

INTERNAL ERROR when using multiple fmt: skip

Open BenjaminBossan opened this issue 2 years ago • 1 comments

Describe the bug

Using multiple # fmt: skip in the same expression causes an INTERNAL ERROR.

To Reproduce

The first example (a) works but all others fail:

a = (
    "this should "  # fmt: skip
    "be fine"
)

b = (
    "this is "  # fmt: skip
    "not working"  # fmt: skip
)

c = (
    "and neither "  # fmt: skip
    "is this "  # fmt: skip
    "working"
)

d = (
    "nor "
    "is this "  # fmt: skip
    "working"  # fmt: skip
)

e = (
    "and this "  # fmt: skip
    "is definitely "
    "not working"  # fmt: skip
)

The resulting error is:

INTERNAL ERROR: Black produced code that is not equivalent to the source

Log:

--- src
+++ dst
@@ -33,11 +33,11 @@
       value=
         Constant(
           kind=
             None,  # NoneType
           value=
-            'this is not working',  # str
+            'this is',  # str
         )  # /Constant
     )  # /Assign
     Assign(
       targets=
         Name(
@@ -52,11 +52,11 @@
       value=
         Constant(
           kind=
             None,  # NoneType
           value=
-            'and neither is this working',  # str
+            'and neither working',  # str
         )  # /Constant
     )  # /Assign
     Assign(
       targets=
         Name(
@@ -71,11 +71,11 @@
       value=
         Constant(
           kind=
             None,  # NoneType
           value=
-            'nor is this working',  # str
+            'nor is this',  # str
         )  # /Constant
     )  # /Assign
     Assign(
       targets=
         Name(
@@ -90,10 +90,10 @@
       value=
         Constant(
           kind=
             None,  # NoneType
           value=
-            'and this is definitely not working',  # str
+            'and this not working',  # str
         )  # /Constant
     )  # /Assign
   type_ignores=
 )  # /Module
\ No newline at end of file

Expected behavior

The lines should be left untouched.

Environment

  • black, 22.12.0 (compiled: yes)
  • Python (CPython) 3.10.9
  • Ubuntu 22.04

Can also be reproduced on https://black.vercel.app.

Additional context

Maybe I'm using fmt: skip incorrectly, but documentation on it is very sparse.

BenjaminBossan avatar Mar 16 '23 14:03 BenjaminBossan

Maybe I got the same here:

error: cannot format serializers.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/lg/s80890fd1ts6s1w69c8lg03m0000gn/T/blk_v5h775n6.log

--- src
+++ dst
@@ -1593,8 +1593,6 @@
     type_ignores=
     TypeIgnore(
     )  # /TypeIgnore
     TypeIgnore(
     )  # /TypeIgnore
-    TypeIgnore(
-    )  # /TypeIgnore
 )  # /Module
\ No newline at end of file

max-wittig avatar Apr 12 '24 14:04 max-wittig