Skip to content

Commit

Permalink
Move to preview style, remove cruft, and add to changelog
Browse files Browse the repository at this point in the history
Signed-off-by: cobalt <[email protected]>
  • Loading branch information
cobaltt7 committed Jan 15, 2025
1 parent e4d8575 commit e4230b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
(#4498)
- Remove parentheses around sole list items (#4312)
- Collapse multiple empty lines after an import into one (#4489)
- Prevent `string_processing` and `wrap_long_dict_values_in_parens` from removing
parenthesis around long dictionary values (#4377)

### Configuration

Expand All @@ -43,6 +45,7 @@
### Performance

<!-- Changes that improve Black's performance. -->

- Speed up the `is_fstring_start` function in Black's tokenizer (#4541)

### Output
Expand Down
23 changes: 11 additions & 12 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,8 @@ def _maybe_split_omitting_optional_parens(
not can_be_split(rhs.body)
and not is_line_short_enough(rhs.body, mode=mode)
and not (
rhs.opening_bracket.parent
Preview.wrap_long_dict_values_in_parens
and rhs.opening_bracket.parent
and rhs.opening_bracket.parent.parent
and rhs.opening_bracket.parent.parent.type == syms.dictsetmaker
)
Expand Down Expand Up @@ -1032,7 +1033,8 @@ def _prefer_split_rhs_oop_over_rhs(

# Retain optional parens around dictionary values
if (
rhs.opening_bracket.parent
Preview.wrap_long_dict_values_in_parens
and rhs.opening_bracket.parent
and rhs.opening_bracket.parent.parent
and rhs.opening_bracket.parent.parent.type == syms.dictsetmaker
and rhs.body.bracket_tracker.delimiters
Expand Down Expand Up @@ -1639,22 +1641,19 @@ def maybe_make_parens_invisible_in_atom(
or is_empty_tuple(node)
or is_one_tuple(node)
or (is_yield(node) and parent.type != syms.expr_stmt)
or (
# This condition tries to prevent removing non-optional brackets
# around a tuple, however, can be a bit overzealous so we provide
# and option to skip this check for `for` and `with` statements.
not remove_brackets_around_comma
and max_delimiter_priority_in_atom(node) >= COMMA_PRIORITY
)
or is_tuple_containing_walrus(node)
or is_tuple_containing_star(node)
or is_generator(node)
):
return False

max_delimiter_priority = max_delimiter_priority_in_atom(node)
# This condition tries to prevent removing non-optional brackets
# around a tuple, however, can be a bit overzealous so we provide
# and option to skip this check for `for` and `with` statements.
if not remove_brackets_around_comma and max_delimiter_priority >= COMMA_PRIORITY:
return False

# if parent.type == syms.dictsetmaker and max_delimiter_priority != 0:
# return False

if is_walrus_assignment(node):
if parent.type in [
syms.annassign,
Expand Down

0 comments on commit e4230b6

Please sign in to comment.