Skip to content

Formatter: parenthesize_long_type_hints preview style #8894

@MichaReiser

Description

@MichaReiser

Implement Black's parenthesize_long_type_hints as a preview style in Ruff.

def foo(
    i: int,
    x: Loooooooooooooooooooooooong
    | Looooooooooooooooong
    | Looooooooooooooooooooong
    | Looooooong,
    *,
    s: str,
) -> None:
    pass

# Formats now to 

def foo(
    i: int,
    x: (
        Loooooooooooooooooooooooong
        | Looooooooooooooooong
        | Looooooooooooooooooooong
        | Looooooong
    ),
    *,
    s: str,
) -> None:
    pass

This seems to be similar to what Ruff used to have but we reverted in #8233. We should investigate why Black isn't breaking the list on the left for

tags: List[str] = [],  # noqa: B006 - ignored by automatic migration, but should be fixed

Which people found ugly. Maybe it's because of #6975?

Metadata

Metadata

Assignees

Labels

formatterRelated to the formatterpreviewRelated to preview mode features

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions