Skip to content

INTERNAL ERROR when using multiple fmt: skip #3608

@BenjaminBossan

Description

@BenjaminBossan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: fmtskipfmt: skip implementationT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions