Skip to content

string_processing: Crash with comment inside implicitly concatenated string (and --line-length 4) #3428

@JelleZijlstra

Description

@JelleZijlstra
inline_comments_func2(
    " this part does not fit into a single line? "
    # x
    "it into parts that fit in line length.",
)

On 22.12.0:

% black --diff tests/data/preview/long_strings.py -l 4 --preview
error: cannot format tests/data/preview/long_strings.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/3b/k964cnv10097wzj3h7w07fww0000gp/T/blk_m7_0sao2.log

Oh no! 💥 💔 💥
1 file would fail to reformat.
% cat /var/folders/3b/k964cnv10097wzj3h7w07fww0000gp/T/blk_m7_0sao2.log
--- src
+++ dst
@@ -2,16 +2,27 @@
   body=
     Expr(
       value=
         Call(
           args=
-            Constant(
-              kind=
-                None,  # NoneType
-              value=
-                'this part does not fit into a single line? it into parts that fit in line length.',  # str
-            )  # /Constant
+            Call(
+              args=
+                Constant(
+                  kind=
+                    None,  # NoneType
+                  value=
+                    'it into parts that fit in line length.',  # str
+                )  # /Constant
+              func=
+                Constant(
+                  kind=
+                    None,  # NoneType
+                  value=
+                    'this part does not fit into a single line?',  # str
+                )  # /Constant
+              keywords=
+            )  # /Call
           func=
             Name(
               ctx=
                 Load(
                 )  # /Load

It appears to insert a function call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.F: stringsRelated to our handling of stringsT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions