Skip to content

Commit

Permalink
Support sets
Browse files Browse the repository at this point in the history
Signed-off-by: cobalt <61329810+cobaltt7@users.noreply.github.com>
  • Loading branch information
cobaltt7 committed Nov 27, 2024
1 parent 84c059c commit 3e34a4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions tests/data/cases/preview_remove_lone_list_item_parens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e34a4c

Please sign in to comment.