wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Forbid implicit `enumerate` calls
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
foriterable as index - variable is adjusted by
1inside the loop's body
Related https://github.com/wemake-services/wemake-python-styleguide/issues/689
This is refactoring pattern. Looks rather complex to me.