Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hug_parens_with_braces_and_square_brackets: Recursively hugging parens decrease readability #4098

Open
MichaReiser opened this issue Dec 10, 2023 · 0 comments
Labels
C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. T: style What do we want Blackened code to look like?

Comments

@MichaReiser
Copy link

MichaReiser commented Dec 10, 2023

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.

@MichaReiser MichaReiser added the T: style What do we want Blackened code to look like? label Dec 10, 2023
@MichaReiser MichaReiser changed the title hug_parens_with_braces_and_square_brackets: Recursively collapsed parens decrease readability hug_parens_with_braces_and_square_brackets: Recursively hugging parens decrease readability Dec 10, 2023
@JelleZijlstra JelleZijlstra added the C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. label Dec 11, 2023
JelleZijlstra added a commit to JelleZijlstra/black that referenced this issue Jan 31, 2024
Primarily because of psf#4036 (a crash) but also because of the feedback
in psf#4098 and psf#4099.
JelleZijlstra added a commit that referenced this issue Feb 2, 2024
…le (#4198)

Primarily because of #4036 (a crash) but also because of the feedback
in #4098 and #4099.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants