sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.5k stars 65 forks source link

Rule `useless-else-on-loop` does not account for `break` statements in nested `for`-loops #386

Closed ruancomelli closed 9 months ago

ruancomelli commented 10 months ago

Checklist

Description

The rule useless-else-on-loop should NOT trigger in the following snippet, but it does:

for thing in things:
    for other_thing in other_things:
        pass  # inner body
    else:
        break
else:
    explode_computer()

rewriting it as

for thing in things:
    for other_thing in other_things:
        pass  # inner body
    else:
        break
explode_computer()

Debug Information

Sourcery Version: 1.8.0

Additional Information

A user reported this bug to our e-mail support.

ruancomelli commented 10 months ago

Additionally, the message "If else clause is always executed move code to same level as loop" is wrong.

ruancomelli commented 9 months ago

This was fixed by v1.10.0.