From 89541d88478d0c7676341b0792360d186d7dfcd5 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 30 Jan 2024 19:37:25 -0800 Subject: [PATCH 1/3] Move hug_parens_with_braces_and_square_brackets into the unstable style Primarily because of #4036 (a crash) but also because of the feedback in #4098 and #4099. --- CHANGES.md | 3 +++ docs/the_black_code_style/future_style.md | 4 ++-- src/black/mode.py | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4fd030df6df..d3e35ca5c3a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,9 @@ +- Move the `hug_parens_with_braces_and_square_brackets` feature to the unstable style + due to an outstanding crash and proposed formatting tweaks (#4198) + ### Configuration diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index d5faae36911..df6202633c7 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -22,8 +22,6 @@ Currently, the following features are included in the preview style: strings - `unify_docstring_detection`: fix inconsistencies in whether certain strings are detected as docstrings -- `hug_parens_with_braces_and_square_brackets`: more compact formatting of nested - brackets ([see below](labels/hug-parens)) - `no_normalize_fmt_skip_whitespace`: whitespace before `# fmt: skip` comments is no longer normalized - `typed_params_trailing_comma`: consistently add trailing commas to typed function @@ -39,6 +37,8 @@ The unstable style additionally includes the following features: ([see below](labels/wrap-long-dict-values)) - `multiline_string_handling`: more compact formatting of expressions involving multiline strings ([see below](labels/multiline-string-handling)) +- `hug_parens_with_braces_and_square_brackets`: more compact formatting of nested + brackets ([see below](labels/hug-parens)) (labels/hug-parens)= diff --git a/src/black/mode.py b/src/black/mode.py index 22352e7c6a8..d1a07694df1 100644 --- a/src/black/mode.py +++ b/src/black/mode.py @@ -179,6 +179,8 @@ class Preview(Enum): typed_params_trailing_comma = auto() +# See https://github.com/psf/black/issues?q=is%3Aissue+is%3Aopen+label%3A%22C%3A+preview+style%22 +# for all open issues with the preview and unstable style. UNSTABLE_FEATURES: Set[Preview] = { # Many issues, see summary in https://github.com/psf/black/issues/4042 Preview.string_processing, @@ -186,6 +188,8 @@ class Preview(Enum): Preview.wrap_long_dict_values_in_parens, # See issue #4159 Preview.multiline_string_handling, + # See issue #4036 (crash), #4098, #4099 (proposed tweaks) + Preview.hug_parens_with_braces_and_square_brackets, } From 064bf1592a8fafb6f059a08bf613d37f21bedef7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 30 Jan 2024 19:42:25 -0800 Subject: [PATCH 2/3] fix --- src/black/mode.py | 2 -- .../cases/preview_hug_parens_with_braces_and_square_brackets.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/black/mode.py b/src/black/mode.py index d1a07694df1..5738bd6b793 100644 --- a/src/black/mode.py +++ b/src/black/mode.py @@ -179,8 +179,6 @@ class Preview(Enum): typed_params_trailing_comma = auto() -# See https://github.com/psf/black/issues?q=is%3Aissue+is%3Aopen+label%3A%22C%3A+preview+style%22 -# for all open issues with the preview and unstable style. UNSTABLE_FEATURES: Set[Preview] = { # Many issues, see summary in https://github.com/psf/black/issues/4042 Preview.string_processing, diff --git a/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets.py b/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets.py index 47a6a0bcae6..cbbcf16d3bd 100644 --- a/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets.py +++ b/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets.py @@ -1,4 +1,4 @@ -# flags: --preview +# flags: --unstable def foo_brackets(request): return JsonResponse( { From 8fe1ea509c8b30310f4bbebb9c37368b7b8ca208 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 30 Jan 2024 19:53:40 -0800 Subject: [PATCH 3/3] fix a test --- ...preview_hug_parens_with_braces_and_square_brackets_no_ll1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py b/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py index fdebdf69c20..16ebea379bc 100644 --- a/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py +++ b/tests/data/cases/preview_hug_parens_with_braces_and_square_brackets_no_ll1.py @@ -1,4 +1,4 @@ -# flags: --preview --no-preview-line-length-1 +# flags: --unstable --no-preview-line-length-1 # split out from preview_hug_parens_with_brackes_and_square_brackets, as it produces # different code on the second pass with line-length 1 in many cases. # Seems to be about whether the last string in a sequence gets wrapped in parens or not.