black
black copied to clipboard
`hug_parens_with_braces_and_square_brackets`: Recursively hugging parens decrease readability
This is feedback related to the hug_parens_with_braces_and_square_brackets preview style.
Describe the style change
Only collapse the first set of parens rather than all parens recursively. Having too many opening/closing parens on a single line makes it harder to distinguish the individual parentheses (especially if they are all of the same kind).
Examples in the current Black style
Here an example from Ruff's shade after implementing the hug_parens_with_braces_and_square_brackets preview style recursively.
)
)
if commented_entity:
- entity_map = CommentedMap(
- [(entity["entity"], entity["value"])]
- )
+ entity_map = CommentedMap([(
+ entity["entity"],
+ entity["value"],
+ )])
entity_map.yaml_add_eol_comment(
commented_entity, entity["entity"]
)
entities.append(entity_map)
else:
entities.append(
- OrderedDict(
- [(entity["entity"], entity["value"])]
- )
+ OrderedDict([(
+ entity["entity"],
+ entity["value"],
+ )])
)
else:
entities.append(
Desired style
)
)
if commented_entity:
entity_map = CommentedMap([
(entity["entity"], entity["value"])
])
entity_map.yaml_add_eol_comment(
commented_entity, entity["entity"]
)
entities.append(entity_map)
else:
entities.append(
OrderedDict([
(entity["entity"], entity["value"])
])
)
else:
entities.append(
Additional context
This issue is split out from my stable style 2024 comment.
Ruff implements hug_parens_with_braces_and_square_brackets in preview style but we intentionally haven't implemented recursive hugging yet.