Skip to content

Bug: PLR1714 auto-fix with multiple conditions #12062

Description

@Spectre5

Ruff removes the a == 1 condition in the example below when applying the (unsafe) auto-fix.

Consider this source as test.py:

def PLR1714_demo():
    a = 1
    b = '2'
    if a == 1 or b == '2' or b == '3':
        pass

Then:

$ ruff --version
ruff 0.4.10
$ ruff check --isolated --select PLR1714 test.py 
test.py:4:8: PLR1714 Consider merging multiple comparisons: `b in ('2', '3')`. Use a `set` if the elements are hashable.
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
$ ruff check --isolated --select PLR1714 --fix --unsafe-fixes test.py 
Found 1 error (1 fixed, 0 remaining).

Now the contents of test.py is shown below, where the conditional a == 1 has been removed.

def PLR1714_demo():
    a = 1
    b = '2'
    if b in ('2', '3'):
        pass

Activity

  1. dhruvmanila commented on Jun 27, 2024

    @dhruvmanila
    Member

    I think this is similar to the bug I found for PLR1701 (which has been removed and redirected to use SIM101) as seen in the PR description.

  2. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    on Jun 27, 2024
  3. charliermarsh commented on Jun 27, 2024

    @charliermarsh
    Member

    Thanks, we'll fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugAn issue describing something that isn't working, or a PR that fixes a bugfixesRelated 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