Skip to content

format: different behavior with black for hug_parens_with_braces_and_square_brackets and generators #11375

@trim21

Description

@trim21

I'm using ruff format with --preview enable, and it generate different output in this case.

ruff:

import shutil
import asyncio


async def main():
    by_path = {}
    loop = asyncio.get_event_loop()

    if loop:
        value = await asyncio.gather(
            *(
                loop.run_in_executor(None, lambda pp: (pp, shutil.disk_usage(pp).free), p)
                for p in by_path
            )
        )
        return value

    return None

black:

import shutil
import asyncio


async def main():
    by_path = {}
    loop = asyncio.get_event_loop()

    if loop:
        value = await asyncio.gather(*(
            loop.run_in_executor(None, lambda pp: (pp, shutil.disk_usage(pp).free), p)
            for p in by_path
        ))
        return value

    return None

This is not listed in "Known Deviations from Black", is this unexpected behavoir?

pyproject.toml

[tool.black]
line-length = 100
target-version = ['py311']
#future = true

unstable = true
preview = true

[tool.ruff]
cache-dir = ".venv/.cache/ruff"
line-length = 100
target-version = 'py311'

exclude = ['dist', '.venv']

[tool.ruff.format]
preview = true

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formatterpreviewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions