From bb31678201e1bebac1c1b7cea038d58db2171b0d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 20 Nov 2023 22:29:44 -0800 Subject: [PATCH] Enable two more --- src/black/linegen.py | 42 +++++++++---------- src/black/mode.py | 4 -- tests/data/cases/expression.py | 4 +- .../data/cases/long_strings_flag_disabled.py | 6 ++- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/black/linegen.py b/src/black/linegen.py index 3fb190e..b53f8c9 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -161,16 +161,15 @@ def visit_default(self, node: LN) -> Iterator[Line]: def visit_test(self, node: Node) -> Iterator[Line]: """Visit an `x if y else z` test""" - if Preview.parenthesize_conditional_expressions in self.mode: - already_parenthesized = ( - node.prev_sibling and node.prev_sibling.type == token.LPAR - ) + already_parenthesized = ( + node.prev_sibling and node.prev_sibling.type == token.LPAR + ) - if not already_parenthesized: - lpar = Leaf(token.LPAR, "") - rpar = Leaf(token.RPAR, "") - node.insert_child(0, lpar) - node.append_child(rpar) + if not already_parenthesized: + lpar = Leaf(token.LPAR, "") + rpar = Leaf(token.RPAR, "") + node.insert_child(0, lpar) + node.append_child(rpar) yield from self.visit_default(node) @@ -230,20 +229,19 @@ def visit_paramspec(self, node: Node) -> Iterator[Line]: node.children[1].prefix = "" def visit_dictsetmaker(self, node: Node) -> Iterator[Line]: - if Preview.wrap_long_dict_values_in_parens in self.mode: - for i, child in enumerate(node.children): - if i == 0: - continue - if node.children[i - 1].type == token.COLON: - if child.type == syms.atom and child.children[0].type == token.LPAR: - if maybe_make_parens_invisible_in_atom( - child, - parent=node, - remove_brackets_around_comma=False, - ): - wrap_in_parentheses(node, child, visible=False) - else: + for i, child in enumerate(node.children): + if i == 0: + continue + if node.children[i - 1].type == token.COLON: + if child.type == syms.atom and child.children[0].type == token.LPAR: + if maybe_make_parens_invisible_in_atom( + child, + parent=node, + remove_brackets_around_comma=False, + ): wrap_in_parentheses(node, child, visible=False) + else: + wrap_in_parentheses(node, child, visible=False) yield from self.visit_default(node) def visit_funcdef(self, node: Node) -> Iterator[Line]: diff --git a/src/black/mode.py b/src/black/mode.py index 124926a..13d8551 100644 --- a/src/black/mode.py +++ b/src/black/mode.py @@ -169,11 +169,7 @@ class Preview(Enum): """Individual preview style features.""" hex_codes_in_unicode_sequences = auto() - # NOTE: string_processing requires wrap_long_dict_values_in_parens - # for https://github.com/psf/black/issues/3117 to be fixed. string_processing = auto() - parenthesize_conditional_expressions = auto() - wrap_long_dict_values_in_parens = auto() hug_parens_with_braces_and_square_brackets = auto() diff --git a/tests/data/cases/expression.py b/tests/data/cases/expression.py index 8e13726..613d2d3 100644 --- a/tests/data/cases/expression.py +++ b/tests/data/cases/expression.py @@ -312,8 +312,8 @@ async def f(): if (1 if super_long_test_name else 2) else (str or bytes or None) ) -{"2.7": dead, "3.7": (long_live or die_hard)} -{"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}} +{"2.7": dead, "3.7": long_live or die_hard} +{"2.7": dead, "3.7": long_live or die_hard, **{"3.6": verygood}} {**a, **b, **c} {"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")} ({"a": "b"}, (True or False), (+value), "string", b"bytes") or None diff --git a/tests/data/cases/long_strings_flag_disabled.py b/tests/data/cases/long_strings_flag_disabled.py index ce60b16..d81c331 100644 --- a/tests/data/cases/long_strings_flag_disabled.py +++ b/tests/data/cases/long_strings_flag_disabled.py @@ -43,8 +43,10 @@ % ( "formatted", "string", - ): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)." - % ("soooo", 2), + ): ( + "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)." + % ("soooo", 2) + ), } func_with_keywords(