Use isinstance() for typechecks.
This commit is contained in:
parent
370685f6b3
commit
64538b2644
9 changed files with 26 additions and 23 deletions
|
@ -165,6 +165,9 @@ enable=F, # Fatal
|
||||||
consider-using-from-import,
|
consider-using-from-import,
|
||||||
consider-using-in,
|
consider-using-in,
|
||||||
consider-using-join,
|
consider-using-join,
|
||||||
|
consider-merging-isinstance,
|
||||||
|
isinstance-second-argument-not-valid-type,
|
||||||
|
unidiomatic-typecheck,
|
||||||
use-list-literal,
|
use-list-literal,
|
||||||
use-dict-literal,
|
use-dict-literal,
|
||||||
useless-object-inheritance,
|
useless-object-inheritance,
|
||||||
|
|
4
convo.py
4
convo.py
|
@ -377,7 +377,7 @@ class PesterText(QtWidgets.QTextEdit):
|
||||||
self.mainwindow = self.parent().mainwindow
|
self.mainwindow = self.parent().mainwindow
|
||||||
else:
|
else:
|
||||||
self.mainwindow = self.parent()
|
self.mainwindow = self.parent()
|
||||||
if type(parent.parent) is PesterTabWindow:
|
if isinstance(parent.parent, PesterTabWindow):
|
||||||
self.tabobject = parent.parent()
|
self.tabobject = parent.parent()
|
||||||
self.hasTabs = True
|
self.hasTabs = True
|
||||||
else:
|
else:
|
||||||
|
@ -514,7 +514,7 @@ class PesterText(QtWidgets.QTextEdit):
|
||||||
imsg = chum.idlemsg(systemColor, window.theme["convo/text/idle"])
|
imsg = chum.idlemsg(systemColor, window.theme["convo/text/idle"])
|
||||||
window.chatlog.log(chum.handle, imsg)
|
window.chatlog.log(chum.handle, imsg)
|
||||||
self.append(convertTags(imsg))
|
self.append(convertTags(imsg))
|
||||||
elif type(lexmsg[0]) is mecmd:
|
elif isinstance(lexmsg[0], mecmd):
|
||||||
memsg = chum.memsg(systemColor, lexmsg)
|
memsg = chum.memsg(systemColor, lexmsg)
|
||||||
if chum is me:
|
if chum is me:
|
||||||
window.chatlog.log(parent.chum.handle, memsg)
|
window.chatlog.log(parent.chum.handle, memsg)
|
||||||
|
|
|
@ -35,7 +35,7 @@ _handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)")
|
||||||
|
|
||||||
class pesterQuirk:
|
class pesterQuirk:
|
||||||
def __init__(self, quirk):
|
def __init__(self, quirk):
|
||||||
if type(quirk) != dict:
|
if not isinstance(quirk, dict):
|
||||||
raise ValueError("Quirks must be given a dictionary")
|
raise ValueError("Quirks must be given a dictionary")
|
||||||
self.quirk = quirk
|
self.quirk = quirk
|
||||||
self.type = self.quirk["type"]
|
self.type = self.quirk["type"]
|
||||||
|
@ -136,9 +136,9 @@ class pesterQuirks:
|
||||||
return [q.quirk for q in self.quirklist]
|
return [q.quirk for q in self.quirklist]
|
||||||
|
|
||||||
def addQuirk(self, q):
|
def addQuirk(self, q):
|
||||||
if type(q) == dict:
|
if isinstance(q, dict):
|
||||||
self.quirklist.append(pesterQuirk(q))
|
self.quirklist.append(pesterQuirk(q))
|
||||||
elif type(q) == pesterQuirk:
|
elif isinstance(q, pesterQuirk):
|
||||||
self.quirklist.append(q)
|
self.quirklist.append(q)
|
||||||
|
|
||||||
def apply(self, lexed, first=False, last=False):
|
def apply(self, lexed, first=False, last=False):
|
||||||
|
|
|
@ -11,10 +11,10 @@ class mysteryTime(timedelta):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return type(other) is mysteryTime
|
return isinstance(other, mysteryTime)
|
||||||
|
|
||||||
def __neq__(self, other):
|
def __neq__(self, other):
|
||||||
return type(other) is not mysteryTime
|
return not isinstance(other, mysteryTime)
|
||||||
|
|
||||||
|
|
||||||
class CaseInsensitiveDict(dict):
|
class CaseInsensitiveDict(dict):
|
||||||
|
|
16
memos.py
16
memos.py
|
@ -32,7 +32,7 @@ QString = str
|
||||||
|
|
||||||
|
|
||||||
def delta2txt(d, format="pc"):
|
def delta2txt(d, format="pc"):
|
||||||
if type(d) is mysteryTime:
|
if isinstance(d, mysteryTime):
|
||||||
return "?"
|
return "?"
|
||||||
if format == "pc":
|
if format == "pc":
|
||||||
sign = "+" if d >= timedelta(0) else "-"
|
sign = "+" if d >= timedelta(0) else "-"
|
||||||
|
@ -117,7 +117,7 @@ class TimeTracker(list):
|
||||||
def __init__(self, time=None):
|
def __init__(self, time=None):
|
||||||
# mysteryTime breaks stuff now, so, uh
|
# mysteryTime breaks stuff now, so, uh
|
||||||
# I'm replacing it with 1 day...
|
# I'm replacing it with 1 day...
|
||||||
if type(time) == mysteryTime:
|
if isinstance(time, mysteryTime):
|
||||||
time = timedelta(microseconds=1)
|
time = timedelta(microseconds=1)
|
||||||
self.timerecord = {"P": [], "F": []}
|
self.timerecord = {"P": [], "F": []}
|
||||||
self.open = {}
|
self.open = {}
|
||||||
|
@ -131,7 +131,7 @@ class TimeTracker(list):
|
||||||
|
|
||||||
def addTime(self, timed):
|
def addTime(self, timed):
|
||||||
# mysteryTime </3
|
# mysteryTime </3
|
||||||
if type(timed) == mysteryTime:
|
if isinstance(timed, mysteryTime):
|
||||||
timed = timedelta(microseconds=1)
|
timed = timedelta(microseconds=1)
|
||||||
try:
|
try:
|
||||||
i = self.index(timed)
|
i = self.index(timed)
|
||||||
|
@ -241,7 +241,7 @@ class TimeInput(QtWidgets.QLineEdit):
|
||||||
def setSlider(self):
|
def setSlider(self):
|
||||||
value = str(self.text())
|
value = str(self.text())
|
||||||
timed = txt2delta(value)
|
timed = txt2delta(value)
|
||||||
if type(timed) is mysteryTime:
|
if isinstance(timed, mysteryTime):
|
||||||
self.timeslider.setValue(0)
|
self.timeslider.setValue(0)
|
||||||
self.setText("?")
|
self.setText("?")
|
||||||
return
|
return
|
||||||
|
@ -306,7 +306,7 @@ class MemoText(PesterText):
|
||||||
self.mainwindow = self.parent().mainwindow
|
self.mainwindow = self.parent().mainwindow
|
||||||
else:
|
else:
|
||||||
self.mainwindow = self.parent()
|
self.mainwindow = self.parent()
|
||||||
if type(parent.parent) is PesterTabWindow:
|
if isinstance(parent.parent, PesterTabWindow):
|
||||||
self.tabobject = parent.parent()
|
self.tabobject = parent.parent()
|
||||||
self.hasTabs = True
|
self.hasTabs = True
|
||||||
else:
|
else:
|
||||||
|
@ -371,7 +371,7 @@ class MemoText(PesterText):
|
||||||
m.start()
|
m.start()
|
||||||
chumdb = window.chumdb
|
chumdb = window.chumdb
|
||||||
if chum is not me: # SO MUCH WH1T3SP4C3 >:]
|
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]
|
colortag = lexmsg[0]
|
||||||
try:
|
try:
|
||||||
color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")])
|
color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")])
|
||||||
|
@ -419,7 +419,7 @@ class MemoText(PesterText):
|
||||||
msg = msg + "</c>"
|
msg = msg + "</c>"
|
||||||
return '<span style="color:#000000">' + msg + "</span>"
|
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())
|
memsg = chum.memsg(systemColor, lexmsg, time=time.getGrammar())
|
||||||
window.chatlog.log(parent.channel, memsg)
|
window.chatlog.log(parent.channel, memsg)
|
||||||
self.append(convertTags(memsg))
|
self.append(convertTags(memsg))
|
||||||
|
@ -721,7 +721,7 @@ class PesterMemo(PesterConvo):
|
||||||
c.setForeground(QtGui.QBrush(color))
|
c.setForeground(QtGui.QBrush(color))
|
||||||
|
|
||||||
def addMessage(self, text, handle):
|
def addMessage(self, text, handle):
|
||||||
if type(handle) is bool:
|
if isinstance(handle, bool):
|
||||||
chum = self.mainwindow.profile()
|
chum = self.mainwindow.profile()
|
||||||
else:
|
else:
|
||||||
chum = PesterProfile(handle)
|
chum = PesterProfile(handle)
|
||||||
|
|
2
menus.py
2
menus.py
|
@ -101,7 +101,7 @@ class PesterQuirkList(QtWidgets.QTreeWidget):
|
||||||
self.changeCheckState()
|
self.changeCheckState()
|
||||||
|
|
||||||
def currentQuirk(self):
|
def currentQuirk(self):
|
||||||
if type(self.currentItem()) is PesterQuirkItem:
|
if isinstance(self.currentItem(), PesterQuirkItem):
|
||||||
return self.currentItem()
|
return self.currentItem()
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -310,10 +310,10 @@ def lexMessage(string):
|
||||||
beginc = 0
|
beginc = 0
|
||||||
endc = 0
|
endc = 0
|
||||||
for o in lexed:
|
for o in lexed:
|
||||||
if type(o) is colorBegin:
|
if isinstance(o, colorBegin):
|
||||||
beginc += 1
|
beginc += 1
|
||||||
balanced.append(o)
|
balanced.append(o)
|
||||||
elif type(o) is colorEnd:
|
elif isinstance(o, colorEnd):
|
||||||
if beginc >= endc:
|
if beginc >= endc:
|
||||||
endc += 1
|
endc += 1
|
||||||
balanced.append(o)
|
balanced.append(o)
|
||||||
|
@ -942,9 +942,9 @@ class parseLeaf:
|
||||||
def expand(self, mo):
|
def expand(self, mo):
|
||||||
out = ""
|
out = ""
|
||||||
for n in self.nodes:
|
for n in self.nodes:
|
||||||
if type(n) == parseLeaf:
|
if isinstance(n, parseLeaf):
|
||||||
out += n.expand(mo)
|
out += n.expand(mo)
|
||||||
elif type(n) == backreference:
|
elif isinstance(n, backreference):
|
||||||
out += mo.group(int(n.number))
|
out += mo.group(int(n.number))
|
||||||
else:
|
else:
|
||||||
out += n
|
out += n
|
||||||
|
|
|
@ -45,7 +45,7 @@ def init(host="127.0.0.1", port=None):
|
||||||
break
|
break
|
||||||
except OSError:
|
except OSError:
|
||||||
raise TwmnError(TwmnError.NO_CONF)
|
raise TwmnError(TwmnError.NO_CONF)
|
||||||
if type(port) == type(""):
|
if isinstance(port, str):
|
||||||
port = int(port)
|
port = int(port)
|
||||||
global s
|
global s
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
|
|
@ -373,7 +373,7 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
|
||||||
self.set("chums", newchums)
|
self.set("chums", newchums)
|
||||||
|
|
||||||
def removeChum(self, chum):
|
def removeChum(self, chum):
|
||||||
if type(chum) is PesterProfile:
|
if isinstance(chum, PesterProfile):
|
||||||
handle = chum.handle
|
handle = chum.handle
|
||||||
else:
|
else:
|
||||||
handle = chum
|
handle = chum
|
||||||
|
@ -605,7 +605,7 @@ class userProfile:
|
||||||
def __init__(self, user):
|
def __init__(self, user):
|
||||||
self.profiledir = _datadir + "profiles"
|
self.profiledir = _datadir + "profiles"
|
||||||
|
|
||||||
if type(user) is PesterProfile:
|
if isinstance(user, PesterProfile):
|
||||||
self.chat = user
|
self.chat = user
|
||||||
self.userprofile = {
|
self.userprofile = {
|
||||||
"handle": user.handle,
|
"handle": user.handle,
|
||||||
|
|
Loading…
Reference in a new issue