Enable two more

This commit is contained in:
Jelle Zijlstra 2023-11-20 22:29:44 -08:00
parent cc3780fd9f
commit bb31678201
4 changed files with 26 additions and 30 deletions

View File

@ -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]:

View File

@ -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()

View File

@ -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

View File

@ -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(