diff --git a/.pylintrc b/.pylintrc index e336a72..f3124d3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -165,6 +165,9 @@ enable=F, # Fatal consider-using-from-import, consider-using-in, consider-using-join, + consider-merging-isinstance, + isinstance-second-argument-not-valid-type, + unidiomatic-typecheck, use-list-literal, use-dict-literal, useless-object-inheritance, diff --git a/convo.py b/convo.py index 8dabefb..23e7ca1 100644 --- a/convo.py +++ b/convo.py @@ -377,7 +377,7 @@ class PesterText(QtWidgets.QTextEdit): self.mainwindow = self.parent().mainwindow else: self.mainwindow = self.parent() - if type(parent.parent) is PesterTabWindow: + if isinstance(parent.parent, PesterTabWindow): self.tabobject = parent.parent() self.hasTabs = True else: @@ -514,7 +514,7 @@ class PesterText(QtWidgets.QTextEdit): imsg = chum.idlemsg(systemColor, window.theme["convo/text/idle"]) window.chatlog.log(chum.handle, imsg) self.append(convertTags(imsg)) - elif type(lexmsg[0]) is mecmd: + elif isinstance(lexmsg[0], mecmd): memsg = chum.memsg(systemColor, lexmsg) if chum is me: window.chatlog.log(parent.chum.handle, memsg) diff --git a/dataobjs.py b/dataobjs.py index f92349c..cfc0c77 100644 --- a/dataobjs.py +++ b/dataobjs.py @@ -35,7 +35,7 @@ _handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)") class pesterQuirk: def __init__(self, quirk): - if type(quirk) != dict: + if not isinstance(quirk, dict): raise ValueError("Quirks must be given a dictionary") self.quirk = quirk self.type = self.quirk["type"] @@ -136,9 +136,9 @@ class pesterQuirks: return [q.quirk for q in self.quirklist] def addQuirk(self, q): - if type(q) == dict: + if isinstance(q, dict): self.quirklist.append(pesterQuirk(q)) - elif type(q) == pesterQuirk: + elif isinstance(q, pesterQuirk): self.quirklist.append(q) def apply(self, lexed, first=False, last=False): diff --git a/generic.py b/generic.py index 020aeeb..a013854 100644 --- a/generic.py +++ b/generic.py @@ -11,10 +11,10 @@ class mysteryTime(timedelta): return self def __eq__(self, other): - return type(other) is mysteryTime + return isinstance(other, mysteryTime) def __neq__(self, other): - return type(other) is not mysteryTime + return not isinstance(other, mysteryTime) class CaseInsensitiveDict(dict): diff --git a/memos.py b/memos.py index 8c942a5..4875645 100644 --- a/memos.py +++ b/memos.py @@ -32,7 +32,7 @@ QString = str def delta2txt(d, format="pc"): - if type(d) is mysteryTime: + if isinstance(d, mysteryTime): return "?" if format == "pc": sign = "+" if d >= timedelta(0) else "-" @@ -117,7 +117,7 @@ class TimeTracker(list): def __init__(self, time=None): # mysteryTime breaks stuff now, so, uh # I'm replacing it with 1 day... - if type(time) == mysteryTime: + if isinstance(time, mysteryTime): time = timedelta(microseconds=1) self.timerecord = {"P": [], "F": []} self.open = {} @@ -131,7 +131,7 @@ class TimeTracker(list): def addTime(self, timed): # mysteryTime :] - if type(lexmsg[0]) is colorBegin: # get color tag + if isinstance(lexmsg[0], colorBegin): # get color tag colortag = lexmsg[0] try: color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")]) @@ -419,7 +419,7 @@ class MemoText(PesterText): msg = msg + "" return '' + msg + "" - if type(lexmsg[0]) is mecmd: + if isinstance(lexmsg[0], mecmd): memsg = chum.memsg(systemColor, lexmsg, time=time.getGrammar()) window.chatlog.log(parent.channel, memsg) self.append(convertTags(memsg)) @@ -721,7 +721,7 @@ class PesterMemo(PesterConvo): c.setForeground(QtGui.QBrush(color)) def addMessage(self, text, handle): - if type(handle) is bool: + if isinstance(handle, bool): chum = self.mainwindow.profile() else: chum = PesterProfile(handle) diff --git a/menus.py b/menus.py index 8468695..491aca8 100644 --- a/menus.py +++ b/menus.py @@ -101,7 +101,7 @@ class PesterQuirkList(QtWidgets.QTreeWidget): self.changeCheckState() def currentQuirk(self): - if type(self.currentItem()) is PesterQuirkItem: + if isinstance(self.currentItem(), PesterQuirkItem): return self.currentItem() else: return None diff --git a/parsetools.py b/parsetools.py index 954c866..1c2c55c 100644 --- a/parsetools.py +++ b/parsetools.py @@ -310,10 +310,10 @@ def lexMessage(string): beginc = 0 endc = 0 for o in lexed: - if type(o) is colorBegin: + if isinstance(o, colorBegin): beginc += 1 balanced.append(o) - elif type(o) is colorEnd: + elif isinstance(o, colorEnd): if beginc >= endc: endc += 1 balanced.append(o) @@ -942,9 +942,9 @@ class parseLeaf: def expand(self, mo): out = "" for n in self.nodes: - if type(n) == parseLeaf: + if isinstance(n, parseLeaf): out += n.expand(mo) - elif type(n) == backreference: + elif isinstance(n, backreference): out += mo.group(int(n.number)) else: out += n diff --git a/pytwmn.py b/pytwmn.py index 641af53..b88023c 100755 --- a/pytwmn.py +++ b/pytwmn.py @@ -45,7 +45,7 @@ def init(host="127.0.0.1", port=None): break except OSError: raise TwmnError(TwmnError.NO_CONF) - if type(port) == type(""): + if isinstance(port, str): port = int(port) global s s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/user_profile.py b/user_profile.py index d50077d..8cc4731 100644 --- a/user_profile.py +++ b/user_profile.py @@ -373,7 +373,7 @@ with a backup from: %s" self.set("chums", newchums) def removeChum(self, chum): - if type(chum) is PesterProfile: + if isinstance(chum, PesterProfile): handle = chum.handle else: handle = chum @@ -605,7 +605,7 @@ class userProfile: def __init__(self, user): self.profiledir = _datadir + "profiles" - if type(user) is PesterProfile: + if isinstance(user, PesterProfile): self.chat = user self.userprofile = { "handle": user.handle,