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

"Black produced different code on the second pass of the formatter." Removing parens recursively in tuple. #963

Closed
Jma353 opened this issue Aug 3, 2019 · 3 comments
Labels
C: unstable formatting Formatting changed on the second pass

Comments

@Jma353
Copy link
Contributor

Jma353 commented Aug 3, 2019

Operating system: macOS Mojave 10.14.6
Python version: Python 3.7.3
Black version: e664517
Does also happen on master: Yes

Unstable formatting:

def example():
    return ((1, ((2))))
--- source
+++ first pass
@@ -1,2 +1,3 @@
 def example():
-    return ((1, ((2))))
+    return (1, (2))
+
--- first pass
+++ second pass
@@ -1,3 +1,3 @@
 def example():
-    return (1, (2))
+    return (1, 2)
@sadovnychyi
Copy link

>>> ((1, ((2)))) == (1, 2)
True

You need to add commas for python to treat it as a tuple.

@JelleZijlstra
Copy link
Collaborator

@sadovnychyi the point of this issue is that Black doesn't remove all the parentheses at once, which leads to a runtime error when running Black. We know that adding an extra set of parentheses doesn't create a tuple.

@JelleZijlstra JelleZijlstra added the C: unstable formatting Formatting changed on the second pass label Aug 12, 2019
@ichard26
Copy link
Collaborator

ichard26 commented Apr 2, 2021

Closing since Black doesn't crash on this on master and stable. While the output still retains a bunch of unnecessary parentheses, whether and how they should be removed can be discussed in #1123.

Thanks for reporting!

@ichard26 ichard26 closed this as completed Apr 2, 2021
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
Projects
None yet
Development

No branches or pull requests

4 participants