Skip to content

Generalize comment handling in flake8-comprehension fixes #4296

@dhruvmanila

Description

@dhruvmanila

I've provided a few examples but there will be a few more. As mentioned that whenever the parenthesis or brackets are being dropped, that's where this will happen. It seems to be happening in most of comprehension fixes.

I believe we should have a generalized way of resolving this.


C404

dict(
    # first comment
    [
        # second comment
        (i, i)
        for i in range(3)
    ]
)

{
    # first comment
    i: i
        for i in range(3)
}

C405

set(
    # some comment
    (1, 2)
)

{1, 2}

C406

dict(
    # first comment
    [
        # second comment
        (1, 2)
    ]
)

{
    # first comment
    1: 2
}

C409

tuple(
    # some comment
    [1, 2, 3, 4]
)

(1, 2, 3, 4)

C410

list(
    # some comment
    [1, 2, 3, 4]
)

[1, 2, 3, 4]

C411

list(
    # comment
    [i * i for i in x]
)

[i * i for i in x]

Originally posted by @dhruvmanila in #4099 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions