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

Running black under Python versions 3.10.15 and 3.10.16 yields different results for parentheses inside case statements #4569

Open
jsolbrig opened this issue Jan 30, 2025 · 1 comment
Labels
T: bug Something isn't working

Comments

@jsolbrig
Copy link

Describe the bug

There is a formatting difference depending on whether you have Python <= 3.10.15 or Python > 3.10.15 installed but with the same version of Black (currently 25.1.0).

Under 3.10.15 this gets reformatted:

match args:
    case _ if ("test" in "testing" and True is True):
        print("YAY")

to this:

match args:
    case _ if "test" in "testing" and True is True:
        print("YAY")

Under 3.10.16 this reformatting doesn't occur and the parentheses remain in place.

The two statements functionally identical so I don't see why it would be reformatted for one version of Python and not for another.

To Reproduce

For example, take this code and call black on it with Python 3.10.15 and 3.10.16 installed. The results will be different.

match args:
    case _ if ("test" in "testing" and True is True):
        print("YAY")

And run it with these arguments:

$ black file.py
  • Black's version: 25.1.0
  • OS and Python version: Linux - Python 3.10.15 and 3.10.16 yield different results

Additional context

@jsolbrig jsolbrig added the T: bug Something isn't working label Jan 30, 2025
@JelleZijlstra
Copy link
Collaborator

I can't reproduce this:

$ ~/.pyenv/versions/3.10.15/bin/python -m black --diff /tmp/issue4569.py 
--- /tmp/issue4569.py	2025-01-31 01:25:45.750911+00:00
+++ /tmp/issue4569.py	2025-01-31 02:05:05.187473+00:00
@@ -1,3 +1,3 @@
 match args:
-    case _ if ("test" in "testing" and True is True):
+    case _ if "test" in "testing" and True is True:
         print("YAY")
would reformat /tmp/issue4569.py

All done! ✨ 🍰 ✨
1 file would be reformatted.
$ ~/.pyenv/versions/3.10.16/bin/python -m black --diff /tmp/issue4569.py 
--- /tmp/issue4569.py	2025-01-31 01:25:45.750911+00:00
+++ /tmp/issue4569.py	2025-01-31 02:05:12.407993+00:00
@@ -1,3 +1,3 @@
 match args:
-    case _ if ("test" in "testing" and True is True):
+    case _ if "test" in "testing" and True is True:
         print("YAY")
would reformat /tmp/issue4569.py

All done! ✨ 🍰 ✨
1 file would be reformatted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants