From e8b026c8caf2c03e016cd76f48fc19a02a4c7211 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 24 Sep 2021 23:06:04 +0200 Subject: [PATCH] DeepSource issue: Implicit enumerate calls found Using `range(len(...))` is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators. Python has a built-in method enumerate which adds a counter to an iterable. Using this, you can access the counter and the value from the iterable at the same time. It is therefore recommended to replace `range(len(...))` with `enumerate(...)`. --- codespell_lib/_codespell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 8103e1ea1b4..8daca5bb4d1 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -551,8 +551,8 @@ def ask_for_word_fix(line, wrongword, misspelling, interactivity): opt = [w.strip() for w in misspelling.data.split(',')] while not r: print("%s Choose an option (blank for none): " % line, end='') - for i in range(len(opt)): - fixword = fix_case(wrongword, opt[i]) + for i, o in enumerate(opt): + fixword = fix_case(wrongword, o) print(" %d) %s" % (i, fixword), end='') print(": ", end='') sys.stdout.flush()