Repository: psf/black

Issue:
experimental-string-processing causing INTERNAL ERROR: Black produced code that is not equivalent to the source
**Describe the bug**
Feeding Black a file containing a string split over several lines can cause an internal error when using experimental-string-processing

**To Reproduce**

1. Take this file<details>
   <summary>File</summary>

   ```py
   (
       "my very long string"
       " that should get formatted"
       " if I'm careful to make sure"
       " it goes over 88 characters which"
       " it has now"
   )
   ```
   </details>
2. Run _Black_ on it with these arguments `--experimental-string-processing`
3. See error

<details>
<summary>Log</summary>

```diff
--- src
+++ dst
@@ -4,10 +4,46 @@
       value=
         Constant(
           kind=
             None,  # NoneType
           value=
-            "my very long string that should get formatted if I'm careful to make sure it goes over 88 characters which it has now",  # str
+            'my very long string',  # str
+        )  # /Constant
+    )  # /Expr
+    Expr(
+      value=
+        Constant(
+          kind=
+            None,  # NoneType
+          value=
+            'that should get formatted',  # str
+        )  # /Constant
+    )  # /Expr
+    Expr(
+      value=
+        Constant(
+          kind=
+            None,  # NoneType
+          value=
+            "if I'm careful to make sure",  # str
+        )  # /Constant
+    )  # /Expr
+    Expr(
+      value=
+        Constant(
+          kind=
+            None,  # NoneType
+          value=
+            'it goes over 88 characters which',  # str
+        )  # /Constant
+    )  # /Expr
+    Expr(
+      value=
+        Constant(
+          kind=
+            None,  # NoneType
+          value=
+            'it has now',  # str
         )  # /Constant
     )  # /Expr
   type_ignores=
 )  # /Module
```
</details>

**Expected behaviour** Black formats the string into two lines as follows:
```py
(
    "my very long string that should get formatted if I'm careful to make sure it "
    "goes over 88 characters which it has now"
)
```

**Environment (please complete the following information):**

- Version: 20.8b2.dev50+g7f75fe3
- OS and Python version: Linux/Python 3.9.0

**Does this bug also happen on master?** Yes



Discussion:
/cc @bbugyi200 

Resolving patch:
diff --git a/src/black/__init__.py b/src/black/__init__.py
--- a/src/black/__init__.py
+++ b/src/black/__init__.py
@@ -3271,7 +3271,8 @@ class StringParenStripper(StringTransformer):
 
     Requirements:
         The line contains a string which is surrounded by parentheses and:
-            - The target string is NOT the only argument to a function call).
+            - The target string is NOT the only argument to a function call.
+            - The target string is NOT a "pointless" string.
             - If the target string contains a PERCENT, the brackets are not
               preceeded or followed by an operator with higher precedence than
               PERCENT.
@@ -3295,6 +3296,14 @@ def do_match(self, line: Line) -> TMatchResult:
             if leaf.type != token.STRING:
                 continue
 
+            # If this is a "pointless" string...
+            if (
+                leaf.parent
+                and leaf.parent.parent
+                and leaf.parent.parent.type == syms.simple_stmt
+            ):
+                continue
+
             # Should be preceded by a non-empty LPAR...
             if (
                 not is_valid_index(idx - 1)


Test patch:
diff --git a/tests/data/long_strings__regression.py b/tests/data/long_strings__regression.py
--- a/tests/data/long_strings__regression.py
+++ b/tests/data/long_strings__regression.py
@@ -375,6 +375,27 @@ def xxxxxxx_xxxxxx(xxxx):
 print(f"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam. {[f'{i}' for i in range(10)]}")
 x = f"This is a long string which contains an f-expr that should not split {{{[i for i in range(5)]}}}."
 
+# The parens should NOT be removed in this case.
+(
+    "my very long string that should get formatted if I'm careful to make sure it goes"
+    " over 88 characters which it has now"
+)
+
+# The parens should NOT be removed in this case.
+(
+    "my very long string that should get formatted if I'm careful to make sure it goes over 88 characters which"
+    " it has now"
+)
+
+# The parens should NOT be removed in this case.
+(
+    "my very long string"
+    " that should get formatted"
+    " if I'm careful to make sure"
+    " it goes over 88 characters which"
+    " it has now"
+)
+
 # output
 
 
@@ -844,3 +865,24 @@ def xxxxxxx_xxxxxx(xxxx):
     "This is a long string which contains an f-expr that should not split"
     f" {{{[i for i in range(5)]}}}."
 )
+
+# The parens should NOT be removed in this case.
+(
+    "my very long string that should get formatted if I'm careful to make sure it goes"
+    " over 88 characters which it has now"
+)
+
+# The parens should NOT be removed in this case.
+(
+    "my very long string that should get formatted if I'm careful to make sure it goes"
+    " over 88 characters which it has now"
+)
+
+# The parens should NOT be removed in this case.
+(
+    "my very long string"
+    " that should get formatted"
+    " if I'm careful to make sure"
+    " it goes over 88 characters which"
+    " it has now"
+)