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

SIM109: Multiple comparisons of same variable #11

Closed
MartinThoma opened this issue Oct 10, 2020 · 1 comment
Closed

SIM109: Multiple comparisons of same variable #11

MartinThoma opened this issue Oct 10, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@MartinThoma
Copy link
Owner

Explanation

Use the "in" operator and a list / tuple instead of multiple comparisons.

Example

# Bad
if a == b or a == c:
    d

# Good
if a in [b, c]:
    d
@MartinThoma MartinThoma added the enhancement New feature or request label Oct 10, 2020
@MartinThoma MartinThoma self-assigned this Oct 10, 2020
@MartinThoma
Copy link
Owner Author

MartinThoma commented Oct 12, 2020

        Expr(
            value=BoolOp(
                op=Or(),
                values=[
                    Compare(
                        left=Name(id='a', ctx=Load()),
                        ops=[Eq()],
                        comparators=[Name(id='b', ctx=Load())],
                    ),
                    Compare(
                        left=Name(id='a', ctx=Load()),
                        ops=[Eq()],
                        comparators=[Name(id='c', ctx=Load())],
                    ),
                ],
            ),
        ),

MartinThoma added a commit that referenced this issue Oct 12, 2020
@MartinThoma MartinThoma changed the title [New Rule] Multiple comparisons of same variable SIM109: Multiple comparisons of same variable Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant