@@ -22,20 +22,47 @@ Currently, the following features are included in the preview style:
2222
2323- ` always_one_newline_after_import ` : Always force one blank line after import
2424 statements, except when the line after the import is a comment or an import statement
25+ - ` wrap_long_dict_values_in_parens ` : Add parentheses around long values in dictionaries
26+ ([ see below] ( labels/wrap-long-dict-values ) )
2527
2628(labels/unstable-features)=
2729
2830The unstable style additionally includes the following features:
2931
3032- ` string_processing ` : split long string literals and related changes
3133 ([ see below] ( labels/string-processing ) )
32- - ` wrap_long_dict_values_in_parens ` : add parentheses to long values in dictionaries
33- ([ see below] ( labels/wrap-long-dict-values ) )
3434- ` multiline_string_handling ` : more compact formatting of expressions involving
3535 multiline strings ([ see below] ( labels/multiline-string-handling ) )
3636- ` hug_parens_with_braces_and_square_brackets ` : more compact formatting of nested
3737 brackets ([ see below] ( labels/hug-parens ) )
3838
39+ (labels/wrap-long-dict-values)=
40+
41+ ### Improved parentheses management in dicts
42+
43+ For dict literals with long values, they are now wrapped in parentheses. Unnecessary
44+ parentheses are now removed. For example:
45+
46+ ``` python
47+ my_dict = {
48+ " a key in my dict" : a_very_long_variable
49+ * and_a_very_long_function_call()
50+ / 100000.0 ,
51+ " another key" : (short_value),
52+ }
53+ ```
54+
55+ will be changed to:
56+
57+ ``` python
58+ my_dict = {
59+ " a key in my dict" : (
60+ a_very_long_variable * and_a_very_long_function_call() / 100000.0
61+ ),
62+ " another key" : short_value,
63+ }
64+ ```
65+
3966(labels/hug-parens)=
4067
4168### Improved multiline dictionary and list indentation for sole function parameter
@@ -122,33 +149,6 @@ exceed the line length limit. Line continuation backslashes are converted into
122149parenthesized strings. Unnecessary parentheses are stripped. The stability and status of
123150this feature istracked in [ this issue] ( https://github.com/psf/black/issues/2188 ) .
124151
125- (labels/wrap-long-dict-values)=
126-
127- ### Improved parentheses management in dicts
128-
129- For dict literals with long values, they are now wrapped in parentheses. Unnecessary
130- parentheses are now removed. For example:
131-
132- ``` python
133- my_dict = {
134- " a key in my dict" : a_very_long_variable
135- * and_a_very_long_function_call()
136- / 100000.0 ,
137- " another key" : (short_value),
138- }
139- ```
140-
141- will be changed to:
142-
143- ``` python
144- my_dict = {
145- " a key in my dict" : (
146- a_very_long_variable * and_a_very_long_function_call() / 100000.0
147- ),
148- " another key" : short_value,
149- }
150- ```
151-
152152(labels/multiline-string-handling)=
153153
154154### Improved multiline string handling
0 commit comments