flake8-simplify icon indicating copy to clipboard operation
flake8-simplify copied to clipboard

[Adjust Rule] SIM113

Open xqt opened this issue 2 years ago • 1 comments

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

xqt avatar Jun 03 '22 19:06 xqt

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

bvidosits avatar Jul 26 '22 17:07 bvidosits