From 9ec4dbd088268563659207184b317b8b3b9d34d2 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Tue, 14 Feb 2023 19:55:23 +0100 Subject: [PATCH] Apply the following pylint messages: - use-list-literal - use-dict-literal - consider-using-in - consider-using-from-import --- .pylintrc | 8 ++++++++ dataobjs.py | 37 ++++++++++++++++++------------------- memos.py | 6 +++--- menus.py | 4 +--- parsetools.py | 2 +- pyinst.py | 12 ++++++------ toast.py | 4 ++-- user_profile.py | 2 +- 8 files changed, 40 insertions(+), 35 deletions(-) diff --git a/.pylintrc b/.pylintrc index 32810f6..315428d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -160,6 +160,14 @@ enable=F, # Fatal wildcard-import, # Specific refactoring checks: use-implicit-booleaness-not-len, + useless-object-inheritance, + consider-using-from-import, + consider-using-in, + consider-using-join, + use-list-literal, + use-dict-literal, + useless-object-inheritance, + useless-return, # Specific basic checks: lost-exception, assert-on-tuple, diff --git a/dataobjs.py b/dataobjs.py index 372ddc4..f92349c 100644 --- a/dataobjs.py +++ b/dataobjs.py @@ -166,7 +166,7 @@ class pesterQuirks: # Exclude option is checked if checkstate == 2: # Check for substring that should be excluded. - excludes = list() + excludes = [] # Check for links, store in list. for match in re.finditer(_urlre, string): excludes.append(match) @@ -189,7 +189,7 @@ class pesterQuirks: if excludes[n].end() > excludes[n + 1].start(): excludes.pop(n) # Seperate parts to be quirked. - sendparts = list() + sendparts = [] # Add string until start of exclude at index 0. until = excludes[0].start() sendparts.append(string[:until]) @@ -203,10 +203,10 @@ class pesterQuirks: sendparts.append(string[after:]) # Quirk to-be-quirked parts. - recvparts = list() + recvparts = [] for part in sendparts: # No split, apply like normal. - if q.type == "regexp" or q.type == "random": + if q.type in ("regexp", "random"): recvparts.append( q.apply(part, first=(i == 0), last=lastStr) ) @@ -227,8 +227,8 @@ class pesterQuirks: string += recvparts[-1] else: # No split, apply like normal. - if q.type != "prefix" and q.type != "suffix": - if q.type == "regexp" or q.type == "random": + if q.type not in ("prefix", "suffix"): + if q.type in ("regexp", "random"): string = q.apply(string, first=(i == 0), last=lastStr) else: string = q.apply(string) @@ -238,8 +238,8 @@ class pesterQuirks: string = q.apply(string) else: # No split, apply like normal. - if q.type != "prefix" and q.type != "suffix": - if q.type == "regexp" or q.type == "random": + if q.type not in ("prefix", "suffix"): + if q.type in ("regexp", "random"): string = q.apply(string, first=(i == 0), last=lastStr) else: string = q.apply(string) @@ -396,22 +396,21 @@ class PesterProfile: ) def memoclosemsg(self, syscolor, initials, verb): - if type(initials) == type(list()): + if isinstance(initials, list): return "{} {}.".format( syscolor.name(), self.colorhtml(), ", ".join(initials), verb, ) - else: - return "{}{}{} {}.".format( - syscolor.name(), - self.colorhtml(), - initials.pcf, - self.initials(), - initials.number, - verb, - ) + return "{}{}{} {}.".format( + syscolor.name(), + self.colorhtml(), + initials.pcf, + self.initials(), + initials.number, + verb, + ) def memonetsplitmsg(self, syscolor, initials): if len(initials) <= 0: @@ -439,7 +438,7 @@ class PesterProfile: def memobanmsg(self, opchum, opgrammar, syscolor, initials, reason): opinit = opgrammar.pcf + opchum.initials() + opgrammar.number - if type(initials) == type(list()): + if isinstance(initials, list): if opchum.handle == reason: return ( "{} banned {} from responding to memo.".format( diff --git a/memos.py b/memos.py index 37744d2..8c942a5 100644 --- a/memos.py +++ b/memos.py @@ -107,7 +107,7 @@ class TimeGrammar: self.temporal = temporal self.pcf = pcf self.when = when - if number == "0" or number == 0: + if number in ("0", 0): self.number = "" else: self.number = str(number) @@ -164,7 +164,7 @@ class TimeTracker(list): except TypeError: # (temporal, pcf, when) = pcfGrammar(mysteryTime()) pcf = pcfGrammar(mysteryTime())[1] - if pcf == "C" or pcf == "?": + if pcf in ("C", "?"): return if timed in self.timerecord[pcf]: return @@ -176,7 +176,7 @@ class TimeTracker(list): pcf = pcfGrammar(timed - timedelta(0))[1] except TypeError: pcf = pcfGrammar(mysteryTime())[1] - if pcf == "C" or pcf == "?": + if pcf in ("C", "?"): return 0 if len(self.timerecord[pcf]) > 1: return self.timerecord[pcf].index(timed) + 1 diff --git a/menus.py b/menus.py index 61555fd..8468695 100644 --- a/menus.py +++ b/menus.py @@ -37,9 +37,7 @@ class PesterQuirkItem(QtWidgets.QTreeWidgetItem): """Sets the order of quirks if auto-sorted by Qt. Obsolete now.""" if self.quirk.type == "prefix": return True - elif ( - self.quirk.type == "replace" or self.quirk.type == "regexp" - ) and quirkitem.type == "suffix": + elif self.quirk.type in ("replace", "regexp") and quirkitem.type == "suffix": return True else: return False diff --git a/parsetools.py b/parsetools.py index 19fb1d3..954c866 100644 --- a/parsetools.py +++ b/parsetools.py @@ -13,7 +13,7 @@ except ImportError: import dataobjs # karxi: My own contribution to this - a proper lexer. -import pnc.lexercon as lexercon +from pnc import lexercon from generic import mysteryTime from quirks import ScriptQuirks from pyquirks import PythonQuirks diff --git a/pyinst.py b/pyinst.py index 9b994c7..eb47b2f 100644 --- a/pyinst.py +++ b/pyinst.py @@ -238,10 +238,10 @@ if (_ARGUMENTS.prompts is not False) and (_ARGUMENTS.prompts != "False"): "This is a script to make building with Pyinstaller a bit more conventient." ) - while (delete_builddist != "y") and (delete_builddist != "n"): + while delete_builddist not in ("y", "n"): delete_builddist = input("Delete build & dist folders? (Y/N): ").lower() - while (upx_enabled != "y") and (upx_enabled != "n"): + while upx_enabled not in ("y", "n"): upx_enabled = input("Enable UPX? (Y/N): ").lower() if upx_enabled == "y": print("If upx is on your path you don't need to include anything here.") @@ -257,14 +257,14 @@ if (_ARGUMENTS.prompts is not False) and (_ARGUMENTS.prompts != "False"): elif upx_enabled == "n": upx_dir = "" - while (windowed != "y") and (windowed != "n"): + while windowed not in ("y", "n"): windowed = input("Build with '--windowed'? (Y/N): ").lower() if sys.platform == "win32": print( "(https://pyinstaller.readthedocs.io/en/stable/usage.html?highlight=sdk#windows)" ) - while (package_universal_crt != "y") and (package_universal_crt != "n"): + while package_universal_crt not in ("y", "n"): package_universal_crt = input( "Try to include universal CRT? (Y/N): " ).lower() @@ -303,8 +303,8 @@ if (_ARGUMENTS.prompts is not False) and (_ARGUMENTS.prompts != "False"): ) print("crt_path = " + crt_path) - if (sys.platform == "win32") or (sys.platform == "linux"): - while (onefile != "y") and (onefile != "n"): + if sys.platform in ("win32", "linux"): + while onefile not in ("y", "n"): onefile = input("Build with '--onefile'? (Y/N): ").lower() except KeyboardInterrupt: diff --git a/toast.py b/toast.py index 8c32aa9..04e914c 100644 --- a/toast.py +++ b/toast.py @@ -93,7 +93,7 @@ class ToastMachine: def show(self): if self.machine.on: # Use libnotify's queue if using libnotify - if self.machine.type == "libnotify" or self.machine.type == "twmn": + if self.machine.type in ("libnotify", "twmn"): self.realShow() elif self.machine.toasts: self.machine.toasts.append(self) @@ -116,7 +116,7 @@ class ToastMachine: extras["parent"] = self.machine.parent if "time" in args: extras["time"] = self.time - if k == "libnotify" or k == "twmn": + if k in ("libnotify", "twmn"): t = v(self.title, self.msg, self.icon, **extras) else: t = v(self.machine, self.title, self.msg, self.icon, **extras) diff --git a/user_profile.py b/user_profile.py index 83e9448..d50077d 100644 --- a/user_profile.py +++ b/user_profile.py @@ -849,7 +849,7 @@ class PesterProfileDB(dict): u = [] for handle, c in chumdict.items(): - options = dict() + options = {} if "group" in c: options["group"] = c["group"] if "notes" in c: