Skip to content

Inconsistent formatting of method call chain with comment #3998

Description

@robmoss

Describe the bug

I noticed what appears to be inconsistent formatting when comparing black's output (v23.10.1) to ruff's new formatter (v0.1.3), as I reported to ruff and can demonstrate here:

x = (
    very_long_function_name_with_many_arguments(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000).f()
    # Comment
    .g()
)
y = (
    very_long_function_name_with_many_arguments(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000).f()
    # Comment
    .g()
    .h()
)

To Reproduce

Black doesn't move .f() to a new line in the first assignment (x = ...) but does move .f() to a new line in the second assignment (y = ...), as shown here:

x = (
    very_long_function_name_with_many_arguments(
        100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
    ).f()
    # Comment
    .g()
)
y = (
    very_long_function_name_with_many_arguments(
        100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
    )
    .f()
    # Comment
    .g()
    .h()
)

Expected behavior

I did not expect that adding/removing the line .h() would affect how .f() is formatted.

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions