Skip to content

Ruff splits subscript targets instead of parenthesizing the value. #13761

@MichaReiser

Description

@MichaReiser
my_object.elemnt[
    0
].subelement = SomeEnumName.VERY_VERY_VERY_LONG_ENUM_VALUE_DESCeeeeeebbbdddddddddddddddddeeeddddd

This is ugly 😓

Black does a better job and formats it as:

my_object.elemnt[0].subelement = (
	SomeEnumName.VERY_VERY_VERY_LONG_ENUM_VALUE_DESCeeeeeebbbdddddddddddddddddeeeddddd
)

Which would align with how subscripts are handled in can_omit_optional_parentheses:

!expr.is_subscript_expr()
&& has_parentheses(expr, context).is_some_and(OwnParentheses::is_non_empty)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformatterRelated to the formatter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions