MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
185 stars 19 forks source link

SIM114: Duplicate blocks in conditionals #10

Closed MartinThoma closed 3 years ago

MartinThoma commented 3 years ago

Explanation

See https://sourcery.ai/blog/explaining-refactorings-4/

Example

# Bad
if a:
    b
elif c:
    b

# Good
if a or c:
    b
MartinThoma commented 3 years ago
        If(
            test=Name(id='a', ctx=Load()),
            body=[
                Expr(
                    value=Name(id='b', ctx=Load()),
                ),
            ],
            orelse=[
                If(
                    test=Name(id='c', ctx=Load()),
                    body=[
                        Expr(
                            value=Name(id='b', ctx=Load()),
                        ),
                    ],
                    orelse=[],
                ),
            ],
        ),