psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
39.16k stars 2.47k forks source link

Black produces different results in different environments for code containing curly braces when used with the same version and options #4390

Closed Iamcerba closed 4 months ago

Iamcerba commented 4 months ago

Describe the bug

Black produces different results in different environments for code containing curly braces when used with the same version and options

To Reproduce

[Linux/Python 3.9.17] or [Windows/Python 3.9.6]

$ black --version

black, 24.4.2 (compiled: yes)
Python (CPython) 3.9.17
$ black --target-version py39 --required-version 24.4.2 --line-length 120 --skip-string-normalization --check --diff --color -c "{}.update({'a': 1,})"

--- STDIN       2024-06-27 11:27:56.582177+00:00
+++ STDOUT      2024-06-27 11:27:56.595058+00:00
@@ -1 +1,3 @@
-{}.update({'a': 1,})
\ No newline at end of file
+{}.update({
+    'a': 1,
+})

[Linux/Python 3.9.19]

$ black --version

black, 24.4.2 (compiled: yes)
Python (CPython) 3.9.19
$ black --target-version py39 --required-version 24.4.2 --line-length 120 --skip-string-normalization --check --diff --color -c "{}.update({'a': 1,})"

--- STDIN   2024-06-27 11:27:51.466634+00:00
+++ STDOUT  2024-06-27 11:27:51.468848+00:00
@@ -1 +1,5 @@
-{}.update({'a': 1,})
\ No newline at end of file
+{}.update(
+    {
+        'a': 1,
+    }
+)

Playground:

Main: image

Stable: image

Expected behavior

Code containing curly braces remains unchanged when formatted with the same version and options on different environments.

Environment

JelleZijlstra commented 4 months ago

I suspect one of your invocations is picking up a configuration file that sets some option. This looks like the hug_parens_with_braces_and_square_brackets unstable feature.

Iamcerba commented 4 months ago

I suspect one of your invocations is picking up a configuration file that sets some option. This looks like the hug_parens_with_braces_and_square_brackets unstable feature.

Thanks a lot, it was helpful. I actually forgot to delete the test config file on local machine with unstable features enabled.