From d39e79dfa06482f8c8e1b88f1ec21896e06dacf1 Mon Sep 17 00:00:00 2001 From: cobalt <61329810+cobaltt7@users.noreply.github.com> Date: Sun, 22 Dec 2024 20:25:54 -0600 Subject: [PATCH] maybe finish it! Signed-off-by: cobalt <61329810+cobaltt7@users.noreply.github.com> --- src/black/linegen.py | 17 ++++++++++------- tests/data/cases/preview_long_dict_values_2.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/black/linegen.py b/src/black/linegen.py index 8359a7a80ff..e397a74bfbb 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -1627,17 +1627,20 @@ 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) ): 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, diff --git a/tests/data/cases/preview_long_dict_values_2.py b/tests/data/cases/preview_long_dict_values_2.py index 3fd4a452d31..bfe46374697 100644 --- a/tests/data/cases/preview_long_dict_values_2.py +++ b/tests/data/cases/preview_long_dict_values_2.py @@ -155,7 +155,7 @@ def bar(): ), } x = { - "foobar": 123 + 456, + "foobar": (123 + 456), } x = { "foobar": (123) + 456,