Skip to content

hug_parens_with_braces_and_square_brackets: Doesn't hug if all entries fit on a line #4099

@MichaReiser

Description

@MichaReiser

Describe the style change

This issue is specific to the new hug_parens_with_braces_and_square_brackets preview style.

Examples in the current Black style

self._edits.append(
    {"operation": "update", "id": index, "fields": list(fields), "region_fields": []}
)

Desired style

self._edits.append({
    "operation": "update", "id": index, "fields": list(fields), "region_fields": []
})

The benefit of the desired style in my view are:

  • It minifies the diff when the length of the entires change because the formatting of the { remain unchanged:

    self._edits.append({
        "operation": "update", 
        "id": index, 
        "fields": list(fields), 
        "region_fields": [], 
        "loooger": "more",
    })

    or

    self._edits.append({ "operation": "update", "id": index, "fields": list(fields)})
  • It feels more consistent with the call expression formatting where the opening are formatted on separated lines (which is necessary to avoid invalid syntax):

    self._edits.append(
        "operation", "update", "id", index, "fields", list(fields), "region_fields", []
    )

Additional context

Originally posted in the stable 2024 style issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions