From ea2164943183aef8ebbcc7381a6bb3d063295086 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 ce820560c5c..8a11e4cdcf1 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -531,8 +531,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()