Use isinstance() for typechecks.

This commit is contained in:
Dpeta 2023-02-15 17:01:27 +01:00
parent 370685f6b3
commit 64538b2644
No known key found for this signature in database
GPG key ID: 51227517CEA0030C
9 changed files with 26 additions and 23 deletions

View file

@ -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,

View file

@ -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)

View file

@ -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):

View file

@ -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):

View file

@ -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 </3
if type(timed) == mysteryTime:
if isinstance(timed, mysteryTime):
timed = timedelta(microseconds=1)
try:
i = self.index(timed)
@ -241,7 +241,7 @@ class TimeInput(QtWidgets.QLineEdit):
def setSlider(self):
value = str(self.text())
timed = txt2delta(value)
if type(timed) is mysteryTime:
if isinstance(timed, mysteryTime):
self.timeslider.setValue(0)
self.setText("?")
return
@ -306,7 +306,7 @@ class MemoText(PesterText):
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:
@ -371,7 +371,7 @@ class MemoText(PesterText):
m.start()
chumdb = window.chumdb
if chum is not me: # SO MUCH WH1T3SP4C3 >:]
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 + "</c>"
return '<span style="color:#000000">' + msg + "</span>"
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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -373,7 +373,7 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
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,