Skip to content

Formatter: inconsistency for parenthesized with with trailing comment #6750

@dhruvmanila

Description

@dhruvmanila

Given:

with (
    open('file')  # trailing
):
    pass


while (
    True  # trailing
):
    pass


match (
    some  # trailing
):
    case (
        pattern  # trailing
    ):
        pass

Formatted as:

with open("file"):  # trailing
    pass


while (
    True  # trailing
):
    pass


match (
    some  # trailing
):
    case (
        pattern  # trailing
    ):
        pass

Notice that for with and case pattern the formatting is not collapsed while it does happen for the rest. The case pattern formatting was adopted from with which is the reason they both are the same.

I think the reason is that the nodes are different i.e, WithItem and Pattern* for with and case pattern while it's an expression for while which can utilize the maybe_parenthesized_expression helper directly.

https://play.ruff.rs/6cacd9e5-03dc-4da7-b185-fb45eb264be4

Metadata

Metadata

Assignees

Labels

acceptedReady for implementationformatterRelated to the formatter

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions