MartinThoma / flake8-simplify

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

SIM110 / SIM111: Use any / all #15

Closed MartinThoma closed 3 years ago

MartinThoma commented 3 years ago

Explanation

It's shorter.

Example 1: any

# Bad
for x in iterable:
    if check(x):
        return True
return False

# Good
return any(check(x) for x in iterable)

Example 2: all

# Bad
for x in iterable:
    if check(x):
        return False
return True

# Good
return all(check(x) for x in iterable)