From 7fbdc950fe43dff90994534cc14658366772fdc9 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 10 Dec 2022 09:08:58 -0800 Subject: [PATCH] Revert "annotation_parens" This reverts commit b6cd780453e7791f4ccace1be4c74ea603192a16. --- src/black/linegen.py | 39 +++++++++++++++++++++------------------ src/black/mode.py | 1 + 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/black/linegen.py b/src/black/linegen.py index ea54705..5901c8f 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -181,27 +181,30 @@ def visit_stmt( def visit_funcdef(self, node: Node) -> Iterator[Line]: """Visit function definition.""" - yield from self.line() + if Preview.annotation_parens not in self.mode: + yield from self.visit_stmt(node, keywords={"def"}, parens=set()) + else: + 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, - ): + # 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: wrap_in_parentheses(node, child, visible=False) - else: - wrap_in_parentheses(node, child, visible=False) - is_return_annotation = 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.""" diff --git a/src/black/mode.py b/src/black/mode.py index 8510b94..138ce11 100644 --- a/src/black/mode.py +++ b/src/black/mode.py @@ -149,6 +149,7 @@ def supports_feature(target_versions: Set[TargetVersion], feature: Feature) -> b class Preview(Enum): """Individual preview style features.""" + annotation_parens = auto() long_docstring_quotes_on_newline = auto() string_processing = auto()