Move wrap_long_dict_values_in_parens
to the preview style (#4561)
This commit is contained in:
parent
459562c71a
commit
3d8129001f
@ -43,6 +43,7 @@ The following changes were not in any previous release:
|
||||
- Collapse multiple empty lines after an import into one (#4489)
|
||||
- Prevent `string_processing` and `wrap_long_dict_values_in_parens` from removing
|
||||
parentheses around long dictionary values (#4377)
|
||||
- Move `wrap_long_dict_values_in_parens` from the unstable to preview style (#4561)
|
||||
|
||||
### Configuration
|
||||
|
||||
|
@ -22,6 +22,8 @@ Currently, the following features are included in the preview style:
|
||||
|
||||
- `always_one_newline_after_import`: Always force one blank line after import
|
||||
statements, except when the line after the import is a comment or an import statement
|
||||
- `wrap_long_dict_values_in_parens`: Add parentheses around long values in dictionaries
|
||||
([see below](labels/wrap-long-dict-values))
|
||||
|
||||
(labels/unstable-features)=
|
||||
|
||||
@ -29,13 +31,38 @@ The unstable style additionally includes the following features:
|
||||
|
||||
- `string_processing`: split long string literals and related changes
|
||||
([see below](labels/string-processing))
|
||||
- `wrap_long_dict_values_in_parens`: add parentheses to long values in dictionaries
|
||||
([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/wrap-long-dict-values)=
|
||||
|
||||
### Improved parentheses management in dicts
|
||||
|
||||
For dict literals with long values, they are now wrapped in parentheses. Unnecessary
|
||||
parentheses are now removed. For example:
|
||||
|
||||
```python
|
||||
my_dict = {
|
||||
"a key in my dict": a_very_long_variable
|
||||
* and_a_very_long_function_call()
|
||||
/ 100000.0,
|
||||
"another key": (short_value),
|
||||
}
|
||||
```
|
||||
|
||||
will be changed to:
|
||||
|
||||
```python
|
||||
my_dict = {
|
||||
"a key in my dict": (
|
||||
a_very_long_variable * and_a_very_long_function_call() / 100000.0
|
||||
),
|
||||
"another key": short_value,
|
||||
}
|
||||
```
|
||||
|
||||
(labels/hug-parens)=
|
||||
|
||||
### 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
|
||||
parenthesized strings. Unnecessary parentheses are stripped. The stability and status of
|
||||
this feature istracked in [this issue](https://github.com/psf/black/issues/2188).
|
||||
|
||||
(labels/wrap-long-dict-values)=
|
||||
|
||||
### Improved parentheses management in dicts
|
||||
|
||||
For dict literals with long values, they are now wrapped in parentheses. Unnecessary
|
||||
parentheses are now removed. For example:
|
||||
|
||||
```python
|
||||
my_dict = {
|
||||
"a key in my dict": a_very_long_variable
|
||||
* and_a_very_long_function_call()
|
||||
/ 100000.0,
|
||||
"another key": (short_value),
|
||||
}
|
||||
```
|
||||
|
||||
will be changed to:
|
||||
|
||||
```python
|
||||
my_dict = {
|
||||
"a key in my dict": (
|
||||
a_very_long_variable * and_a_very_long_function_call() / 100000.0
|
||||
),
|
||||
"another key": short_value,
|
||||
}
|
||||
```
|
||||
|
||||
(labels/multiline-string-handling)=
|
||||
|
||||
### Improved multiline string handling
|
||||
|
@ -208,8 +208,6 @@ class Preview(Enum):
|
||||
UNSTABLE_FEATURES: set[Preview] = {
|
||||
# Many issues, see summary in https://github.com/psf/black/issues/4042
|
||||
Preview.string_processing,
|
||||
# See issues #3452 and #4158
|
||||
Preview.wrap_long_dict_values_in_parens,
|
||||
# See issue #4159
|
||||
Preview.multiline_string_handling,
|
||||
# See issue #4036 (crash), #4098, #4099 (proposed tweaks)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# flags: --unstable
|
||||
# flags: --preview
|
||||
x = {
|
||||
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
|
||||
"xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx"
|
||||
@ -287,15 +287,17 @@ def bar():
|
||||
|
||||
class Random:
|
||||
def func():
|
||||
random_service.status.active_states.inactive = make_new_top_level_state_from_dict({
|
||||
"topLevelBase": {
|
||||
"secondaryBase": {
|
||||
"timestamp": 1234,
|
||||
"latitude": 1,
|
||||
"longitude": 2,
|
||||
"actionTimestamp": (
|
||||
Timestamp(seconds=1530584000, nanos=0).ToJsonString()
|
||||
),
|
||||
}
|
||||
},
|
||||
})
|
||||
random_service.status.active_states.inactive = make_new_top_level_state_from_dict(
|
||||
{
|
||||
"topLevelBase": {
|
||||
"secondaryBase": {
|
||||
"timestamp": 1234,
|
||||
"latitude": 1,
|
||||
"longitude": 2,
|
||||
"actionTimestamp": (
|
||||
Timestamp(seconds=1530584000, nanos=0).ToJsonString()
|
||||
),
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -1,9 +1,9 @@
|
||||
# flags: --unstable
|
||||
# This is testing an issue that is specific to the unstable style (wrap_long_dict_values_in_parens)
|
||||
# flags: --preview
|
||||
# This is testing an issue that is specific to the preview style (wrap_long_dict_values_in_parens)
|
||||
{
|
||||
"is_update": (up := commit.hash in update_hashes)
|
||||
}
|
||||
|
||||
# output
|
||||
# This is testing an issue that is specific to the unstable style (wrap_long_dict_values_in_parens)
|
||||
# This is testing an issue that is specific to the preview style (wrap_long_dict_values_in_parens)
|
||||
{"is_update": (up := commit.hash in update_hashes)}
|
||||
|
Loading…
Reference in New Issue
Block a user