flake8-simplify
flake8-simplify copied to clipboard
[Adjust Rule] SIM113
Desired change
- Rule(s): SIM113
- Adjustment: The rule must be ignored if the counter variable is modified inside the loop and does not just count the loops
Example
This is an example where the mentioned rule(s) would currently be suboptimal:
i = 0
for page in pagegenerators.YearPageGenerator(start, end, site):
self.assertIsInstance(page, pywikibot.Page)
self.assertEqual(date.formatYear(site.lang, start + i),
page.title())
self.assertNotEqual(page.title(), '0')
i += 1
if start + i == 0:
i += 1
Explanation
In the last line the counter variable i
is adjusted. This is not the same as the value set by enumerate
A simpler example in my case:
def test():
success = 0 # Use enumerate for 'success' flake8(SIM113)
failure = 0
for foo in bar:
try:
do_something(foo)
except Exception:
failure += 1
continue
success += 1