Skip to content

# fmt: skip ignored inside multi-part if-clause #4730

@ElkMonster

Description

@ElkMonster

Describe the bug

#fmt: skip is ignored in the specific case demonstrated below.

Edit: Actually, thinking about it again I realised that (to me), the actual bug is that black changes the code at all. However, I'd already be happy if I could at least keep it from disfiguring my code via fmt: skip.

To Reproduce

Let black format this piece of code:

class ClassWithALongName:
    Constant1 = 1
    Constant2 = 2
    Constant3 = 3


def test():
    if (
        "cond1" == "cond1"
        and "cond2" == "cond2"
        and 1 in (  # fmt: skip
            ClassWithALongName.Constant1,
            ClassWithALongName.Constant2,
            ClassWithALongName.Constant3,
        )
    ):
        return True
    return False

Expected behavior

Leave the line marked with # fmt: skip unchanged.
Instead, it moves the in to the next line, which I find confusing and hard to read:

def test():
    if (
        "cond1" == "cond1"
        and "cond2" == "cond2"
        and 1
        in (  # fmt: skip
            ClassWithALongName.Constant1,
            ClassWithALongName.Constant2,
            ClassWithALongName.Constant3,
        )
    ):
        return True
    return False

Environment

Arch Linux
black, 25.1.0 (compiled: no)
Python (CPython) 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: fmtskipfmt: skip implementationT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions