Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: PLR1714 auto-fix with multiple conditions #12062

Open
Spectre5 opened this issue Jun 27, 2024 · 2 comments
Open

Bug: PLR1714 auto-fix with multiple conditions #12062

Spectre5 opened this issue Jun 27, 2024 · 2 comments
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@Spectre5
Copy link

Spectre5 commented Jun 27, 2024

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
@dhruvmanila
Copy link
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.

@dhruvmanila dhruvmanila added the bug Something isn't working label Jun 27, 2024
@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Jun 27, 2024
@charliermarsh
Copy link
Member

Thanks, we'll fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

No branches or pull requests

3 participants