From 3e34a4cc0ce355ab0e17304808ff617470f8afbd Mon Sep 17 00:00:00 2001 From: cobalt <61329810+cobaltt7@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:41:09 -0600 Subject: [PATCH] Support sets Signed-off-by: cobalt <61329810+cobaltt7@users.noreply.github.com> --- src/black/linegen.py | 11 +++++++---- .../cases/preview_remove_lone_list_item_parens.py | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/black/linegen.py b/src/black/linegen.py index a868c885218..7bd018d31af 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -512,11 +512,14 @@ def visit_atom(self, node: Node) -> Iterator[Line]: if ( Preview.remove_lone_list_item_parens in self.mode and len(node.children) == 3 - and node.children[0].type == token.LSQB - and node.children[-1].type == token.RSQB ): - # Lists of one item - maybe_make_parens_invisible_in_atom(node.children[1], parent=node) + first = node.children[0] + last = node.children[-1] + if (first.type == token.LSQB and last.type == token.RSQB) or ( + first.type == token.LBRACE and last.type == token.RBRACE + ): + # Lists or sets of one item + maybe_make_parens_invisible_in_atom(node.children[1], parent=node) yield from self.visit_default(node) diff --git a/tests/data/cases/preview_remove_lone_list_item_parens.py b/tests/data/cases/preview_remove_lone_list_item_parens.py index 4b296d29ea5..ad7058ba179 100644 --- a/tests/data/cases/preview_remove_lone_list_item_parens.py +++ b/tests/data/cases/preview_remove_lone_list_item_parens.py @@ -5,6 +5,9 @@ items = [(((((True,)))))] items = [((((()))))] items = [(x for x in [1])] +items = {(123)} +items = {(True)} +items = {(((((True)))))} # Requires `hug_parens_with_braces_and_square_brackets` unstable style to remove parentheses # around multiline values @@ -85,6 +88,9 @@ items = [(True,)] items = [()] items = [(x for x in [1])] +items = {123} +items = {True} +items = {True} # Requires `hug_parens_with_braces_and_square_brackets` unstable style to remove parentheses # around multiline values