Skip to content

PLR1714: Repeated equality comparison to the same literal value shouldn't convert to a set #21692

@injust

Description

@injust

Summary

Observed this in and split it out of #21690.

def test(foo: str) -> None:
    if foo == "bar" or foo == "bar":
        pass

https://play.ruff.rs/40871aec-3cf3-48fd-b42f-76f1b8c4118f

PLR1714 changes this to:

def test(foo: str) -> None:
    if foo in {"bar", "bar"}:
        pass

If the values being compared are literals, the equality comparisons should be merged instead of converting to a set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing 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