Black: Comments in a dict: "Black produced different code on the second pass"

Created on 22 Mar 2018  路  5Comments  路  Source: psf/black

Operating system: macOS High Sierra
Python version: 3.6.4
Black version: black==18.3a3
Does also happen on master: Yes

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',

# Latex figure (float) alignment
#'figure_align': 'htbp',
}
$ black 2.py
error: cannot format 2.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/ambv/black/issues.  This diff might be helpful: /var/folders/kt/j77sf4_n6fnbx6pg199rbx700000gn/T/blk_zqa031lp.log
--- source
+++ first pass
@@ -1,15 +1,10 @@
-latex_elements = {
-# The paper size ('letterpaper' or 'a4paper').
-#'papersize': 'letterpaper',
+latex_elements = {}
+    # The paper size ('letterpaper' or 'a4paper').
+    # 'papersize': 'letterpaper',
+    # The font size ('10pt', '11pt' or '12pt').
+    # 'pointsize': '10pt',
+    # Additional stuff for the LaTeX preamble.
+    # 'preamble': '',
+    # Latex figure (float) alignment
+    # 'figure_align': 'htbp',

-# The font size ('10pt', '11pt' or '12pt').
-#'pointsize': '10pt',
-
-# Additional stuff for the LaTeX preamble.
-#'preamble': '',
-
-# Latex figure (float) alignment
-#'figure_align': 'htbp',
-}
-
-

--- first pass
+++ second pass
@@ -1,10 +1,10 @@
 latex_elements = {}
-    # The paper size ('letterpaper' or 'a4paper').
-    # 'papersize': 'letterpaper',
-    # The font size ('10pt', '11pt' or '12pt').
-    # 'pointsize': '10pt',
-    # Additional stuff for the LaTeX preamble.
-    # 'preamble': '',
-    # Latex figure (float) alignment
-    # 'figure_align': 'htbp',
+# The paper size ('letterpaper' or 'a4paper').
+# 'papersize': 'letterpaper',
+# The font size ('10pt', '11pt' or '12pt').
+# 'pointsize': '10pt',
+# Additional stuff for the LaTeX preamble.
+# 'preamble': '',
+# Latex figure (float) alignment
+# 'figure_align': 'htbp',


bug comments unstable formatting

All 5 comments

Maybe related to #22 and #62.

You reported this one already in #27. Since this one has a better title and a more compact example, I'll close the other one as a duplicate.

Something similar:


# IN

transformed = im.transform(im.size, Image.QUAD,
                           (0, 0, 0, h // 2,
                            # ul -> ccw around quad:
                            w // 2, h // 2, w // 2, 0),
                           Image.BILINEAR)

# OUT

transformed = im.transform(
    im.size,
    Image.QUAD,
    (0, 0, 0, h // 2, w // 2, h // 2, w // 2, 0),
    # ul -> ccw around quad:
    Image.BILINEAR,
)

came here to report something similar where https://github.com/elastic/elasticsearch-py/blob/master/example/load.py#L31-L46 gets squashed to a single line and all the comments appended after.

Do you want a separate issue for the squashing (edit: this is #22, feel free to ignore)? The resulting line is 190 chars long and definitely doesn't look good.

Thank you!

relevant diff (other changes omitted):

diff --git a/example/load.py b/example/load.py
index c218e95..1566dec 100644
--- a/example/load.py
+++ b/example/load.py
@@ -28,36 +28,25 @@ def create_git_index(client, index):
     }

     create_index_body = {
-      'settings': {
+        'settings': {'number_of_shards': 1, 'number_of_replicas': 0, 'analysis': {'analyzer': {'file_path': {'type': 'custom', 'tokenizer': 'path_hierarchy', 'filter': ['lowercase']}}}},
         # just one shard, no replicas for testing
-        'number_of_shards': 1,
-        'number_of_replicas': 0,
-
         # custom analyzer for analyzing file paths
-        'analysis': {
-          'analyzer': {
-            'file_path': {
-              'type': 'custom',
-              'tokenizer': 'path_hierarchy',
-              'filter': ['lowercase']
+        'mappings': {
+            'doc': {
+                'properties': {
+                    'repository': {'type': 'keyword'},
+                    'author': user_mapping,
+                    'authored_date': {'type': 'date'},
+                    'committer': user_mapping,
+                    'committed_date': {'type': 'date'},
+                    'parent_shas': {'type': 'keyword'},
+                    'description': {'type': 'text', 'analyzer': 'snowball'},
+                    'files': {
+                        'type': 'text', 'analyzer': 'file_path', "fielddata": True
+                    },
+                }
             }
-          }
-        }
-      },
-      'mappings': {
-        'doc': {
-          'properties': {
-            'repository': {'type': 'keyword'},
-            'author': user_mapping,
-            'authored_date': {'type': 'date'},
-            'committer': user_mapping,
-            'committed_date': {'type': 'date'},
-            'parent_shas': {'type': 'keyword'},
-            'description': {'type': 'text', 'analyzer': 'snowball'},
-            'files': {'type': 'text', 'analyzer': 'file_path', "fielddata": True}
-          }
-        }
-      }
+        },
     }

     # create empty index

BTW, this is fixed in 18.4a0.

Was this page helpful?
0 / 5 - 0 ratings