add annotation_parens

This commit is contained in:
Jelle Zijlstra 2022-12-17 19:04:04 -08:00
parent 23840a5331
commit c5fc62d371
2 changed files with 18 additions and 22 deletions

View File

@ -200,30 +200,27 @@ def visit_dictsetmaker(self, node: Node) -> Iterator[Line]:
def visit_funcdef(self, node: Node) -> Iterator[Line]:
"""Visit function definition."""
if Preview.annotation_parens not in self.mode:
yield from self.visit_stmt(node, keywords={"def"}, parens=set())
else:
yield from self.line()
yield from self.line()
# Remove redundant brackets around return type annotation.
is_return_annotation = False
for child in node.children:
if child.type == token.RARROW:
is_return_annotation = True
elif is_return_annotation:
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:
# Remove redundant brackets around return type annotation.
is_return_annotation = False
for child in node.children:
if child.type == token.RARROW:
is_return_annotation = True
elif is_return_annotation:
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)
is_return_annotation = False
else:
wrap_in_parentheses(node, child, visible=False)
is_return_annotation = False
for child in node.children:
yield from self.visit(child)
for child in node.children:
yield from self.visit(child)
def visit_match_case(self, node: Node) -> Iterator[Line]:
"""Visit either a match or case statement."""

View File

@ -149,7 +149,6 @@ def supports_feature(target_versions: Set[TargetVersion], feature: Feature) -> b
class Preview(Enum):
"""Individual preview style features."""
annotation_parens = auto()
prefer_splitting_right_hand_side_of_assignments = auto()
# NOTE: string_processing requires wrap_long_dict_values_in_parens
# for https://github.com/psf/black/issues/3117 to be fixed.