Skip to content

PLR1714 doesn't check for Yoda conditions #5987

@dosisod

Description

@dosisod

See #1348 (comment).

Ruff doesn't detect Yoda conditions for the following:

x = ""

_ = x == "abc" or "def" == x
_ = "abc" == x or "def" == x
_ = "abc" == x or x == "def"

Ruff doesn't output anything.

For comparison, Refurb outputs errors for each line:

$ refurb x.py
x.py:3:5 [FURB108]: Replace `x == y or z == x` with `x in (y, z)`
x.py:4:5 [FURB108]: Replace `x == y or z == y` with `y in (x, z)`
x.py:5:5 [FURB108]: Replace `x == y or y == z` with `y in (x, z)`

If you disable/don't fix the Yoda errors you won't get the PLR1714 errors. If you do fix the Yoda errors, you will get the proper/expected error, PLR1714.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions