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

INTERNAL ERROR: Black produced different code on the second pass of the formatter. #2049

Closed
andrewdotn opened this issue Mar 16, 2021 · 2 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

@andrewdotn
Copy link

When trying to format a file, I got an error message telling me to report the issue here.

To Reproduce

  1. Take this file
def x():
    assert y(
        [
            {"blahblah": ["blahblahblahblah"]}
        ],
        [{"blahblah": ["blahblahblahblah"]}],
        [{"blahblah": ["blahblahblahblah"]}]
    ) == {"x": "a", "y":  []}
  1. Run Black on it with these arguments: black foo.py
  2. See error

Expected behavior

No error message

Environment:

  • Version: master @ 20.8b2.dev111+g5446a92f0161
  • OS and Python version: macOS 11, Python 3.9.1

Additional context Add any other context about the problem here.

Mode(target_versions={<TargetVersion.PY38: 8>, <TargetVersion.PY36: 6>, <TargetVersion.PY37: 7>}, line_length=88, string_normalization=True, magic_trailing_comma=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,9 +1,6 @@
 def x():
     assert y(
-        [
-            {"blahblah": ["blahblahblahblah"]}
-        ],
         [{"blahblah": ["blahblahblahblah"]}],
-        [{"blahblah": ["blahblahblahblah"]}]
-    ) == {"x": "a", "y":  []}
-
+        [{"blahblah": ["blahblahblahblah"]}],
+        [{"blahblah": ["blahblahblahblah"]}],
+    ) == {"x": "a", "y": []}
--- first pass
+++ second pass
@@ -1,6 +1,9 @@
 def x():
-    assert y(
-        [{"blahblah": ["blahblahblahblah"]}],
-        [{"blahblah": ["blahblahblahblah"]}],
-        [{"blahblah": ["blahblahblahblah"]}],
-    ) == {"x": "a", "y": []}
+    assert (
+        y(
+            [{"blahblah": ["blahblahblahblah"]}],
+            [{"blahblah": ["blahblahblahblah"]}],
+            [{"blahblah": ["blahblahblahblah"]}],
+        )
+        == {"x": "a", "y": []}
+    )
@andrewdotn andrewdotn added the T: bug Something isn't working label Mar 16, 2021
@klieret
Copy link

klieret commented Mar 18, 2021

Hi @andrewdotn : I can confirm this is happening also for other versions.

But for anyone stuck with this issue: You can work around it by simply adding the missing comma that black wanted to add in its first pass.

@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Mar 19, 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

3 participants