From 13f120b029c75aa600b989620be5635da8d47c5b Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Fri, 17 Feb 2023 02:22:50 +0100 Subject: [PATCH] Use enumerate instead of range+len for loops. --- .pylintrc | 1 + dataobjs.py | 4 ++-- pesterchum.py | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.pylintrc b/.pylintrc index f3124d3..ffef98c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -166,6 +166,7 @@ enable=F, # Fatal consider-using-in, consider-using-join, consider-merging-isinstance, + consider-using-enumerate, isinstance-second-argument-not-valid-type, unidiomatic-typecheck, use-list-literal, diff --git a/dataobjs.py b/dataobjs.py index 22b2bc1..ef0c5b4 100644 --- a/dataobjs.py +++ b/dataobjs.py @@ -221,9 +221,9 @@ class pesterQuirks: # print("excludes: " + str(excludes)) # print("sendparts: " + str(sendparts)) # print("recvparts: " + str(recvparts)) - for part in range(0, len(excludes)): + for part, exclude in enumerate(excludes): string += recvparts[part] - string += excludes[part].group() + string += exclude.group() string += recvparts[-1] else: # No split, apply like normal. diff --git a/pesterchum.py b/pesterchum.py index f470e29..9582db7 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -3880,8 +3880,8 @@ class PesterWindow(MovingWindow): read_file = server_file.read() server_file.close() server_list_obj = json.loads(read_file) - for i in range(len(server_list_obj)): - server_list_items.append(server_list_obj[i]["server"]) + for server in server_list_obj: + server_list_items.append(server["server"]) except: if not self.chooseServerAskedToReset: self.chooseServerAskedToReset = True @@ -3898,8 +3898,8 @@ class PesterWindow(MovingWindow): selected_entry = self.removeServerBox.currentIndex() except (IndexError, AssertionError) as e: PchumLog.warning(e) - for i in range(len(server_list_obj)): - if server_list_obj[i]["server"] == self.removeServerBox.currentText(): + for i, server in enumerate(server_list_obj): + if server["server"] == self.removeServerBox.currentText(): selected_entry = i if selected_entry is not None: @@ -3994,8 +3994,8 @@ class PesterWindow(MovingWindow): with open(_datadir + "serverlist.json") as server_file: read_file = server_file.read() server_obj = json.loads(read_file) - for i in range(len(server_obj)): - server_list_items.append(server_obj[i]["server"]) + for server in server_obj: + server_list_items.append(server["server"]) except: if not self.chooseServerAskedToReset: self.chooseServerAskedToReset = True @@ -4010,8 +4010,8 @@ class PesterWindow(MovingWindow): # removeServerBox self.removeServerBox = QtWidgets.QComboBox() - for i in range(len(server_list_items)): - self.removeServerBox.addItem(server_list_items[i]) + for server in server_list_items: + self.removeServerBox.addItem(server) # Buttons cancel = QtWidgets.QPushButton("CANCEL") @@ -4069,8 +4069,8 @@ class PesterWindow(MovingWindow): except (IndexError, AssertionError) as e: # fallback using 'server' as primary key PchumLog.warning(e) - for i in range(len(server_obj)): - if server_obj[i]["server"] == self.serverBox.currentText(): + for i, server in enumerate(server_obj): + if server["server"] == self.serverBox.currentText(): selected_entry = i try: @@ -4116,8 +4116,8 @@ class PesterWindow(MovingWindow): with open(_datadir + "serverlist.json") as server_file: read_file = server_file.read() server_obj = json.loads(read_file) - for i in range(len(server_obj)): - server_list_items.append(server_obj[i]["server"]) + for server in server_obj: + server_list_items.append(server["server"]) except: PchumLog.exception("") if not self.chooseServerAskedToReset: @@ -4133,8 +4133,8 @@ class PesterWindow(MovingWindow): # Serverbox self.serverBox = QtWidgets.QComboBox() - for i in range(len(server_list_items)): - self.serverBox.addItem(server_list_items[i]) + for server in server_list_items: + self.serverBox.addItem(server) self.serverBox.addItem("Add a server [Prompt]") self.serverBox.addItem("Remove a server [Prompt]")