Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTERNAL ERROR: Black produced different code on the second pass of the formatter. #1945

Closed
Linekio opened this issue Jan 27, 2021 · 3 comments
Labels
C: unstable formatting Formatting changed on the second pass R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@Linekio
Copy link

Linekio commented Jan 27, 2021

I produced the minimal code "az.py":

class Foo:

    def bar(self, length_18_variable):
        if cond1:
            while cond2:
                length_18_variable = aaaa(length_18_variable.bbbb, length_18_variable.cccc, length_18_variable.ddd) + r(a=1)
black az.py
error: cannot format az.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_qdnb6p5f.log

here the diff file:

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,8 +1,9 @@
-
 class Foo:
-
     def bar(self, length_18_variable):
         if cond1:
             while cond2:
-                length_18_variable = aaaa(length_18_variable.bbbb, length_18_variable.cccc, length_18_variable.ddd) + r(a=1)
-
+                length_18_variable = aaaa(
+                    length_18_variable.bbbb,
+                    length_18_variable.cccc,
+                    length_18_variable.ddd,
+                ) + r(a=1)
--- first pass
+++ second pass
@@ -1,9 +1,12 @@
 class Foo:
     def bar(self, length_18_variable):
         if cond1:
             while cond2:
-                length_18_variable = aaaa(
-                    length_18_variable.bbbb,
-                    length_18_variable.cccc,
-                    length_18_variable.ddd,
-                ) + r(a=1)
+                length_18_variable = (
+                    aaaa(
+                        length_18_variable.bbbb,
+                        length_18_variable.cccc,
+                        length_18_variable.ddd,
+                    )
+                    + r(a=1)
+                )

black, version 20.8b1
Linuxmint 20 cinnamon
python3.8.5

This bug also happen on master

@Linekio Linekio added the T: bug Something isn't working label Jan 27, 2021
@jonadaly
Copy link

I have what looks like the same problem (20.8b1):

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -85,11 +85,16 @@
     if end_date:
-        midnight_next_day: datetime = datetime(end_date.year, end_date.month, end_date.day, tzinfo=timezone.utc) + timedelta(days=1)
+        midnight_next_day: datetime = datetime(
+            end_date_parsed.year,
+            end_date_parsed.month,
+            end_date_parsed.day,
+            tzinfo=timezone.utc,
+        ) + timedelta(days=1)

--- first pass
+++ second pass
@@ -85,16 +85,19 @@
     if end_date:
-        midnight_next_day: datetime = datetime(
-            end_date.year,
-            end_date.month,
-            end_date.day,
-            tzinfo=timezone.utc,
-        ) + timedelta(days=1)
+        midnight_next_day: datetime = (
+            datetime(
+                end_date_parsed.year,
+                end_date_parsed.month,
+                end_date_parsed.day,
+                tzinfo=timezone.utc,
+            )
+            + timedelta(days=1)
+        )

@adalke
Copy link

adalke commented Jan 29, 2021

Same here, also with 20.8b1.

% cat case1.py
msg = ("Could not %(decoder_name)s decode tag %(tag)r value %(encoded_fp)s: %(err)s, %(where)s" %
           dict(decoder_name="A", tag=args.fp_tag,
               where=location.where(), err=err, encoded_fp="A"))
% black case1.py
error: cannot format case1.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter. ...
% cat /var/folders/7h/qqvrpj2j5tl4q72w4q815pyc0000gq/T/blk_kk6lssnu.log
Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,3 +1,10 @@
-msg = ("Could not %(decoder_name)s decode tag %(tag)r value %(encoded_fp)s: %(err)s, %(where)s" %
-           dict(decoder_name="A", tag=args.fp_tag,
-               where=location.where(), err=err, encoded_fp="A"))
+msg = (
+    "Could not %(decoder_name)s decode tag %(tag)r value %(encoded_fp)s: %(err)s, %(where)s"
+    % dict(
+        decoder_name="A",
+        tag=args.fp_tag,
+        where=location.where(),
+        err=err,
+        encoded_fp="A",
+    )
+)
--- first pass
+++ second pass
@@ -1,10 +1,7 @@
-msg = (
-    "Could not %(decoder_name)s decode tag %(tag)r value %(encoded_fp)s: %(err)s, %(where)s"
-    % dict(
-        decoder_name="A",
-        tag=args.fp_tag,
-        where=location.where(),
-        err=err,
-        encoded_fp="A",
-    )
+msg = "Could not %(decoder_name)s decode tag %(tag)r value %(encoded_fp)s: %(err)s, %(where)s" % dict(
+    decoder_name="A",
+    tag=args.fp_tag,
+    where=location.where(),
+    err=err,
+    encoded_fp="A",
 )

and the same error message with:

% cat case2.py
def f():
    return "Options(skip_ids=%r, show_ids=%r, show_id_indices=%r, skip_fps=%r, show_fps=%r)" % (
           self.skip_ids, self.show_ids, self.show_id_indices, self.skip_fps, self.show_fps)
% cat /var/folders/7h/qqvrpj2j5tl4q72w4q815pyc0000gq/T/blk_9qb5q853.log
Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,3 +1,11 @@
 def f():
-    return "Options(skip_ids=%r, show_ids=%r, show_id_indices=%r, skip_fps=%r, show_fps=%r)" % (
-           self.skip_ids, self.show_ids, self.show_id_indices, self.skip_fps, self.show_fps)
+    return (
+        "Options(skip_ids=%r, show_ids=%r, show_id_indices=%r, skip_fps=%r, show_fps=%r)"
+        % (
+            self.skip_ids,
+            self.show_ids,
+            self.show_id_indices,
+            self.skip_fps,
+            self.show_fps,
+        )
+    )
--- first pass
+++ second pass
@@ -1,11 +1,8 @@
 def f():
-    return (
-        "Options(skip_ids=%r, show_ids=%r, show_id_indices=%r, skip_fps=%r, show_fps=%r)"
-        % (
-            self.skip_ids,
-            self.show_ids,
-            self.show_id_indices,
-            self.skip_fps,
-            self.show_fps,
-        )
+    return "Options(skip_ids=%r, show_ids=%r, show_id_indices=%r, skip_fps=%r, show_fps=%r)" % (
+        self.skip_ids,
+        self.show_ids,
+        self.show_id_indices,
+        self.skip_fps,
+        self.show_fps,
     )

@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Apr 1, 2021
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Apr 25, 2021
@ichard26
Copy link
Collaborator

Hello!

All reproduction cases in this issue format without error on master. The fixing commit was 8672af3 from PR GH-2126. I'll be marking this issue as a duplicate of GH-1629 since that's what GH-2126 aimed to fix and it's highly likely this issue falls under GH-1629.

Since we use the issue tracker as a reflection of what's on master, I'll be closing this issue. If you have any issues, especially with the new (but stable) output, please open a new issue. Oh and the fix should be available in a published release soon, see GH-2125 for more info.

Thank you for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: unstable formatting Formatting changed on the second pass R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants