Skip to content

FBT001 Boolean trap surprising false negative with bool | None #7487

@leddy231

Description

@leddy231

FBT001 should catch boolean positional arguments in function definitions, but to my surprise it does not care about bool | None, which I would expect it to do. Thinking about it, I would expect it to catch any union type where bool is one of the options.

In both cases, FBT003 triggers on the call to the function, but the function definition itself passes.

def chaught(x: bool) -> bool:
    """FBT0001 trigger."""
    return x


def passes(x: bool | None) -> bool | None:
    """No FBT0001 trigger."""
    return x


chaught(True) #FBT003 trigger
passes(False) #FBT003 trigger

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions