Skip to content

Trailing parenthesized function return type comment becomes leading comment #13369

@MichaReiser

Description

@MichaReiser
def foo(
    arg: (  # comment with non-return annotation
        int
        # comment with non-return annotation
    ),
):
    pass


def foo(
    arg: (  # comment with non-return annotation
        int
        | range
        | memoryview
        # comment with non-return annotation
    ),
):
    pass

def foo(arg: (
        int
        # only after
)):
    pass

Output

def foo(
    # comment with non-return annotation
    # comment with non-return annotation
    arg: (int),
):
    pass


def foo(
    # comment with non-return annotation
    # comment with non-return annotation
    arg: (int | range | memoryview),
):
    pass


def foo(
    # only after
    arg: (int),
):
    pass

Found by going through the tests in psf/black#4453

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