Tadaboody / good_smell

A linting/refactoring library for python best practices and lesser-known tricks
BSD 3-Clause "New" or "Revised" License
30 stars 3 forks source link

Use dropwhile #56

Closed Tadaboody closed 5 years ago

Tadaboody commented 5 years ago

New smell

Smelly code

for x in iterable:
    # No body
    if pred(x):
        continue
    # Body

Fixed code

import itertools
for x in itertools.dropwhile(pred,iterable):
    # Body

Why is it smelly?

Old for had iteration logic in the body, where business logic should be

Tadaboody commented 5 years ago

The behavior isn't actually the same. An if-continue is more along the lines of filterfalse