wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Forbid implicit `enumerate` calls

Open sobolevn opened this issue 5 years ago • 0 comments

Rule request

Thesis

This code should raise:

x = 0
for i in items:
    x += 1
    print(items[x])

But, it is not!

Why is it a bad idea? We are using some mutable state from outside world, when we can just use enumerate.

How to detect this pattern?

  • variable is assigned as 0
  • variable then is used on for iterable as index
  • variable is adjusted by 1 inside the loop's body

Related https://github.com/wemake-services/wemake-python-styleguide/issues/689

This is refactoring pattern. Looks rather complex to me.

sobolevn avatar Mar 03 '20 12:03 sobolevn