From 70ea19e839f2eaada3eb326e083ef7cc00e28a46 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Sun, 19 Feb 2023 19:04:16 +0100 Subject: [PATCH 1/4] "QString" --> str --- convo.py | 4 +-- irc.py | 32 +++++++++---------- memos.py | 6 ++-- pesterchum.py | 88 +++++++++++++++++++++++++-------------------------- 4 files changed, 65 insertions(+), 65 deletions(-) diff --git a/convo.py b/convo.py index 5e7a629..2ee33dc 100644 --- a/convo.py +++ b/convo.py @@ -1152,8 +1152,8 @@ class PesterConvo(QtWidgets.QFrame): def toggleMute(self, toggled): self.notifications_muted = toggled - messageSent = QtCore.pyqtSignal("QString", "QString") - windowClosed = QtCore.pyqtSignal("QString") + messageSent = QtCore.pyqtSignal(str, str) + windowClosed = QtCore.pyqtSignal(str) aligndict = { "h": { diff --git a/irc.py b/irc.py index 5cf1aaf..371c327 100644 --- a/irc.py +++ b/irc.py @@ -1019,22 +1019,22 @@ class PesterIRC(QtCore.QThread): """ "METADATA DRAFT numeric reply 770 RPL_METADATASUBOK, we subbed to a key.""" PchumLog.info("_metadatasubok: %s", params) - moodUpdated = QtCore.pyqtSignal("QString", Mood) - colorUpdated = QtCore.pyqtSignal("QString", QtGui.QColor) - messageReceived = QtCore.pyqtSignal("QString", "QString") - memoReceived = QtCore.pyqtSignal("QString", "QString", "QString") - noticeReceived = QtCore.pyqtSignal("QString", "QString") - inviteReceived = QtCore.pyqtSignal("QString", "QString") - timeCommand = QtCore.pyqtSignal("QString", "QString", "QString") - namesReceived = QtCore.pyqtSignal("QString", PesterList) + moodUpdated = QtCore.pyqtSignal(str, Mood) + colorUpdated = QtCore.pyqtSignal(str, QtGui.QColor) + messageReceived = QtCore.pyqtSignal(str, str) + memoReceived = QtCore.pyqtSignal(str, str, str) + noticeReceived = QtCore.pyqtSignal(str, str) + inviteReceived = QtCore.pyqtSignal(str, str) + timeCommand = QtCore.pyqtSignal(str, str, str) + namesReceived = QtCore.pyqtSignal(str, PesterList) channelListReceived = QtCore.pyqtSignal(PesterList) - nickCollision = QtCore.pyqtSignal("QString", "QString") - getSvsnickedOn = QtCore.pyqtSignal("QString", "QString") - myHandleChanged = QtCore.pyqtSignal("QString") - chanInviteOnly = QtCore.pyqtSignal("QString") - modesUpdated = QtCore.pyqtSignal("QString", "QString") + nickCollision = QtCore.pyqtSignal(str, str) + getSvsnickedOn = QtCore.pyqtSignal(str, str) + myHandleChanged = QtCore.pyqtSignal(str) + chanInviteOnly = QtCore.pyqtSignal(str) + modesUpdated = QtCore.pyqtSignal(str, str) connected = QtCore.pyqtSignal() askToConnect = QtCore.pyqtSignal(Exception) - userPresentUpdate = QtCore.pyqtSignal("QString", "QString", "QString") - cannotSendToChan = QtCore.pyqtSignal("QString", "QString") - signal_forbiddenchannel = QtCore.pyqtSignal("QString", "QString") + userPresentUpdate = QtCore.pyqtSignal(str, str, str) + cannotSendToChan = QtCore.pyqtSignal(str, str) + signal_forbiddenchannel = QtCore.pyqtSignal(str, str) diff --git a/memos.py b/memos.py index abf778f..27767a0 100644 --- a/memos.py +++ b/memos.py @@ -1461,7 +1461,7 @@ class PesterMemo(PesterConvo): def closeInviteOnly(self, channel): c = str(channel) if c.lower() == self.channel.lower(): - self.mainwindow.inviteOnlyChan["QString"].disconnect(self.closeInviteOnly) + self.mainwindow.inviteOnlyChan[str].disconnect(self.closeInviteOnly) if self.parent(): PchumLog.info(self.channel) i = self.parent().tabIndices[self.channel] @@ -1484,7 +1484,7 @@ class PesterMemo(PesterConvo): def closeForbidden(self, channel, reason): c = str(channel) if c.lower() == self.channel.lower(): - self.mainwindow.forbiddenChan["QString", "QString"].disconnect( + self.mainwindow.forbiddenChan[str, str].disconnect( self.closeForbidden ) if self.parent(): @@ -2040,7 +2040,7 @@ class PesterMemo(PesterConvo): self.mainwindow.waitingMessages.messageAnswered(self.channel) self.windowClosed.emit(self.title()) - windowClosed = QtCore.pyqtSignal("QString") + windowClosed = QtCore.pyqtSignal(str) timelist = [ diff --git a/pesterchum.py b/pesterchum.py index 9dc911f..b38c436 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -1152,8 +1152,8 @@ class chumArea(RightClickTree): self.takeItem(chumLabel) self.addItem(chumLabel) - removeChumSignal = QtCore.pyqtSignal("QString") - blockChumSignal = QtCore.pyqtSignal("QString") + removeChumSignal = QtCore.pyqtSignal(str) + blockChumSignal = QtCore.pyqtSignal(str) class trollSlum(chumArea): @@ -1295,13 +1295,13 @@ class TrollSlumWindow(QtWidgets.QFrame): self.blockChumSignal.emit(handle) self.addtrolldialog = None - blockChumSignal = QtCore.pyqtSignal("QString") - unblockChumSignal = QtCore.pyqtSignal("QString") + blockChumSignal = QtCore.pyqtSignal(str) + unblockChumSignal = QtCore.pyqtSignal(str) class PesterWindow(MovingWindow): disconnectIRC = QtCore.pyqtSignal() - sendMessage = QtCore.pyqtSignal("QString", "QString") + sendMessage = QtCore.pyqtSignal(str, str) def __init__(self, options, parent=None, app=None): super().__init__( @@ -1596,8 +1596,8 @@ class PesterWindow(MovingWindow): self.chumList.itemActivated[QtWidgets.QTreeWidgetItem, int].connect( self.pesterSelectedChum ) - self.chumList.removeChumSignal["QString"].connect(self.removeChum) - self.chumList.blockChumSignal["QString"].connect(self.blockChum) + self.chumList.removeChumSignal[str].connect(self.removeChum) + self.chumList.blockChumSignal[str].connect(self.blockChum) self.addChumButton = QtWidgets.QPushButton( self.theme["main/addchum/text"], self @@ -1662,7 +1662,7 @@ class PesterWindow(MovingWindow): # if not ostools.isOSXLeopard(): # QtCore.QTimer.singleShot(1000, self.mspacheck) - self.pcUpdate["QString", "QString"].connect(self.updateMsg) + self.pcUpdate[str, str].connect(self.updateMsg) self.mychumhandleLabel.adjustSize() # Required so "CHUMHANDLE:" regardless of style-sheet. self.moodsLabel.adjustSize() # Required so "MOOD:" regardless of style-sheet. @@ -2027,10 +2027,10 @@ class PesterWindow(MovingWindow): self.tabconvo.show() else: convoWindow = PesterConvo(chum, initiated, self) - convoWindow.messageSent["QString", "QString"].connect( - self.sendMessage["QString", "QString"] + convoWindow.messageSent[str, str].connect( + self.sendMessage[str, str] ) - convoWindow.windowClosed["QString"].connect(self.closeConvo) + convoWindow.windowClosed[str].connect(self.closeConvo) self.convos[chum.handle] = convoWindow if chum.handle.upper() in BOTNAMES or self.config.irc_compatibility_mode(): convoWindow.toggleQuirks(True) @@ -2134,15 +2134,15 @@ class PesterWindow(MovingWindow): else: memoWindow = PesterMemo(channel, timestr, self, None) # connect signals - self.inviteOnlyChan["QString"].connect(memoWindow.closeInviteOnly) - self.forbiddenChan["QString", "QString"].connect(memoWindow.closeForbidden) - memoWindow.messageSent["QString", "QString"].connect( - self.sendMessage["QString", "QString"] + self.inviteOnlyChan[str].connect(memoWindow.closeInviteOnly) + self.forbiddenChan[str, str].connect(memoWindow.closeForbidden) + memoWindow.messageSent[str, str].connect( + self.sendMessage[str, str] ) - memoWindow.windowClosed["QString"].connect(self.closeMemo) - self.namesUpdated["QString"].connect(memoWindow.namesUpdated) - self.modesUpdated["QString", "QString"].connect(memoWindow.modesUpdated) - self.userPresentSignal["QString", "QString", "QString"].connect( + memoWindow.windowClosed[str].connect(self.closeMemo) + self.namesUpdated[str].connect(memoWindow.namesUpdated) + self.modesUpdated[str, str].connect(memoWindow.modesUpdated) + self.userPresentSignal[str, str, str].connect( memoWindow.userPresentChange ) # chat client send memo open @@ -3098,8 +3098,8 @@ class PesterWindow(MovingWindow): self.allusers = PesterUserlist(self.config, self.theme, self) self.allusers.accepted.connect(self.userListClose) self.allusers.rejected.connect(self.userListClose) - self.allusers.addChum["QString"].connect(self.userListAdd) - self.allusers.pesterChum["QString"].connect(self.userListPester) + self.allusers.addChum[str].connect(self.userListAdd) + self.allusers.pesterChum[str].connect(self.userListPester) self.requestNames.emit("#pesterchum") self.allusers.show() @@ -3613,8 +3613,8 @@ class PesterWindow(MovingWindow): return trolls = [PesterProfile(h) for h in self.config.getBlocklist()] self.trollslum = TrollSlumWindow(trolls, self) - self.trollslum.blockChumSignal["QString"].connect(self.blockChum) - self.trollslum.unblockChumSignal["QString"].connect(self.unblockChum) + self.trollslum.blockChumSignal[str].connect(self.blockChum) + self.trollslum.unblockChumSignal[str].connect(self.unblockChum) self.moodsRequest.emit(PesterList(trolls)) self.trollslum.show() @@ -4215,41 +4215,41 @@ class PesterWindow(MovingWindow): if ret == QtWidgets.QMessageBox.StandardButton.Yes: self.parent.restartIRC(verify_hostname=False) - pcUpdate = QtCore.pyqtSignal("QString", "QString") + pcUpdate = QtCore.pyqtSignal(str, str) closeToTraySignal = QtCore.pyqtSignal() - newConvoStarted = QtCore.pyqtSignal("QString", bool, name="newConvoStarted") - sendMessage = QtCore.pyqtSignal("QString", "QString") - sendNotice = QtCore.pyqtSignal("QString", "QString") - sendCTCP = QtCore.pyqtSignal("QString", "QString") - convoClosed = QtCore.pyqtSignal("QString") + newConvoStarted = QtCore.pyqtSignal(str, bool, name="newConvoStarted") + sendMessage = QtCore.pyqtSignal(str, str) + sendNotice = QtCore.pyqtSignal(str, str) + sendCTCP = QtCore.pyqtSignal(str, str) + convoClosed = QtCore.pyqtSignal(str) profileChanged = QtCore.pyqtSignal() animationSetting = QtCore.pyqtSignal(bool) moodRequest = QtCore.pyqtSignal(PesterProfile) moodsRequest = QtCore.pyqtSignal(PesterList) moodUpdated = QtCore.pyqtSignal() requestChannelList = QtCore.pyqtSignal() - requestNames = QtCore.pyqtSignal("QString") - namesUpdated = QtCore.pyqtSignal("QString") - modesUpdated = QtCore.pyqtSignal("QString", "QString") - userPresentSignal = QtCore.pyqtSignal("QString", "QString", "QString") + requestNames = QtCore.pyqtSignal(str) + namesUpdated = QtCore.pyqtSignal(str) + modesUpdated = QtCore.pyqtSignal(str, str) + userPresentSignal = QtCore.pyqtSignal(str, str, str) mycolorUpdated = QtCore.pyqtSignal() trayIconSignal = QtCore.pyqtSignal(int) - blockedChum = QtCore.pyqtSignal("QString") - unblockedChum = QtCore.pyqtSignal("QString") - kickUser = QtCore.pyqtSignal("QString", "QString", "QString") - joinChannel = QtCore.pyqtSignal("QString") - leftChannel = QtCore.pyqtSignal("QString") - setChannelMode = QtCore.pyqtSignal("QString", "QString", "QString") - channelNames = QtCore.pyqtSignal("QString") - inviteChum = QtCore.pyqtSignal("QString", "QString") - inviteOnlyChan = QtCore.pyqtSignal("QString") - forbiddenChan = QtCore.pyqtSignal("QString", "QString") + blockedChum = QtCore.pyqtSignal(str) + unblockedChum = QtCore.pyqtSignal(str) + kickUser = QtCore.pyqtSignal(str, str, str) + joinChannel = QtCore.pyqtSignal(str) + leftChannel = QtCore.pyqtSignal(str) + setChannelMode = QtCore.pyqtSignal(str, str, str) + channelNames = QtCore.pyqtSignal(str) + inviteChum = QtCore.pyqtSignal(str, str) + inviteOnlyChan = QtCore.pyqtSignal(str) + forbiddenChan = QtCore.pyqtSignal(str, str) closeSignal = QtCore.pyqtSignal() disconnectIRC = QtCore.pyqtSignal() gainAttention = QtCore.pyqtSignal(QtWidgets.QWidget) pingServer = QtCore.pyqtSignal() setAway = QtCore.pyqtSignal(bool) - killSomeQuirks = QtCore.pyqtSignal("QString", "QString") + killSomeQuirks = QtCore.pyqtSignal(str, str) class PesterTray(QtWidgets.QSystemTrayIcon): From f6c5c1e8047f299c491e53a3d6cc939fd04ef678 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Sun, 19 Feb 2023 19:36:53 +0100 Subject: [PATCH 2/4] Replace QString with str --- memos.py | 13 +++++------ menus.py | 11 +++++---- parsetools.py | 3 +-- pesterchum.py | 62 +++++++++++++++++++++++++-------------------------- 4 files changed, 41 insertions(+), 48 deletions(-) diff --git a/memos.py b/memos.py index 27767a0..5872ca3 100644 --- a/memos.py +++ b/memos.py @@ -30,9 +30,6 @@ PchumLog = logging.getLogger("pchumLogger") _valid_memo_msg_start = re.compile( r"^([A-Z]{3}):\s" ) -# Python 3 -QString = str - def delta2txt(d, format="pc"): if isinstance(d, mysteryTime): @@ -1439,7 +1436,7 @@ class PesterMemo(PesterConvo): irc_compatible=self.mainwindow.config.irc_compatibility_mode(), ) - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def namesUpdated(self, channel): c = str(channel) if c.lower() != self.channel.lower(): @@ -1451,13 +1448,13 @@ class PesterMemo(PesterConvo): for n in self.mainwindow.namesdb[self.channel]: self.addUser(n) - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def modesUpdated(self, channel, modes): PchumLog.debug("modesUpdated(%s, %s)", channel, modes) if channel.lower() == self.channel.lower(): self.updateChanModes(modes, None) - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def closeInviteOnly(self, channel): c = str(channel) if c.lower() == self.channel.lower(): @@ -1480,7 +1477,7 @@ class PesterMemo(PesterConvo): msgbox.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Ok) msgbox.exec() - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def closeForbidden(self, channel, reason): c = str(channel) if c.lower() == self.channel.lower(): @@ -1571,7 +1568,7 @@ class PesterMemo(PesterConvo): self.mainwindow.chatlog.log(self.channel, msg) del self.netsplit - @QtCore.pyqtSlot(QString, QString, QString) + @QtCore.pyqtSlot(str, str, str) def userPresentChange(self, handle, channel, update): # print("handle: %s, channel: %s, update: %s" % (handle, channel, update)) h = str(handle) diff --git a/menus.py b/menus.py index 5a4e9bc..d51dfcb 100644 --- a/menus.py +++ b/menus.py @@ -19,7 +19,6 @@ from version import _pcVersion from convo import PesterInput, PesterText from parsetools import lexMessage -QString = str _datadir = ostools.getDataDir() # Logger PchumLog = logging.getLogger("pchumLogger") @@ -1815,7 +1814,7 @@ class PesterUserlist(QtWidgets.QDialog): self.searchbox = QtWidgets.QLineEdit(self) # self.searchbox.setStyleSheet(theme["convo/input/style"]) # which style is better? self.searchbox.setPlaceholderText("Search") - self.searchbox.textChanged["QString"].connect(self.updateUsers) + self.searchbox.textChanged[str].connect(self.updateUsers) self.label = QtWidgets.QLabel("USERLIST") self.userarea = RightClickList(self) @@ -1847,7 +1846,7 @@ class PesterUserlist(QtWidgets.QDialog): self.mainwindow.namesUpdated.connect(self.updateUsers) - self.mainwindow.userPresentSignal["QString", "QString", "QString"].connect( + self.mainwindow.userPresentSignal[str, str, str].connect( self.updateUserPresent ) self.updateUsers() @@ -1876,7 +1875,7 @@ class PesterUserlist(QtWidgets.QDialog): self.userarea.addItem(item) self.userarea.sortItems() - @QtCore.pyqtSlot(QString, QString, QString) + @QtCore.pyqtSlot(str, str, str) def updateUserPresent(self, handle, channel, update): h = str(handle) c = str(channel) @@ -1928,8 +1927,8 @@ class PesterUserlist(QtWidgets.QDialog): return self.pesterChum.emit(cur.text()) - addChum = QtCore.pyqtSignal("QString") - pesterChum = QtCore.pyqtSignal("QString") + addChum = QtCore.pyqtSignal(str) + pesterChum = QtCore.pyqtSignal(str) class MemoListItem(QtWidgets.QTreeWidgetItem): diff --git a/parsetools.py b/parsetools.py index cdf1d1f..3718938 100644 --- a/parsetools.py +++ b/parsetools.py @@ -24,7 +24,6 @@ PchumLog = logging.getLogger("pchumLogger") # I'll clean up the things that are no longer needed once the transition is # actually finished. -QString = str _ctag_begin = re.compile(r"(?i)") # _gtag_begin = re.compile(r"(?i)") @@ -829,7 +828,7 @@ def kxhandleInput(ctx, text=None, flavor=None, irc_compatible=False): # if ceased, rebegin if hasattr(ctx, "chumopen") and not ctx.chumopen: if not irc_compatible: - ctx.mainwindow.newConvoStarted.emit(QString(ctx.title()), True) + ctx.mainwindow.newConvoStarted.emit(str(ctx.title()), True) ctx.setChumOpen(True) # Post-process and send the messages. diff --git a/pesterchum.py b/pesterchum.py index b38c436..af70252 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -163,8 +163,6 @@ BOTNAMES.extend(SERVICES) _CONSOLE = False _CONSOLE_ENV = {} _CONSOLE_ENV["PAPP"] = None -# Python 3 -QString = str # Command line arguments _ARGUMENTS = parser.parse_args() @@ -1211,7 +1209,7 @@ class trollSlum(chumArea): # TypeError: connect() failed between triggered(bool) and unblockChumSignal() # I'm not sure why this was here in the first place- # Does removing it break anything else...? - # unblockChumSignal = QtCore.pyqtSignal('QString') + # unblockChumSignal = QtCore.pyqtSignal(str) class TrollSlumWindow(QtWidgets.QFrame): @@ -1707,7 +1705,7 @@ class PesterWindow(MovingWindow): # We probably tried to interact with a call not available on this kernel. PchumLog.exception("") - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def updateMsg(self, ver, url): if not hasattr(self, "updatemenu"): self.updatemenu = None @@ -2032,13 +2030,13 @@ class PesterWindow(MovingWindow): ) convoWindow.windowClosed[str].connect(self.closeConvo) self.convos[chum.handle] = convoWindow - if chum.handle.upper() in BOTNAMES or self.config.irc_compatibility_mode(): + if chum.handle.upper() in BOTNAMES: convoWindow.toggleQuirks(True) convoWindow.quirksOff.setChecked(True) - if str(chum.handle).upper() in CUSTOMBOTS: - self.newConvoStarted.emit(QString(chum.handle), initiated) + if not self.config.irc_compatibility_mode() or chum.handle.upper() in CUSTOMBOTS: + self.newConvoStarted.emit(chum.handle, initiated) else: - self.newConvoStarted.emit(QString(chum.handle), initiated) + self.newConvoStarted.emit(chum.handle, initiated) convoWindow.show() def createTabWindow(self): @@ -2608,7 +2606,7 @@ class PesterWindow(MovingWindow): chum.color = color self.newConversation(chum) - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def closeConvo(self, handle): h = str(handle) try: @@ -2633,7 +2631,7 @@ class PesterWindow(MovingWindow): self.chatlog.finish(h) del self.convos[h] - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def closeMemo(self, channel): c = str(channel) self.chatlog.finish(c) @@ -2656,28 +2654,28 @@ class PesterWindow(MovingWindow): del self.tabmemo self.tabmemo = None - @QtCore.pyqtSlot(QString, Mood) + @QtCore.pyqtSlot(str, Mood) def updateMoodSlot(self, handle, mood): h = str(handle) self.updateMood(h, mood) - @QtCore.pyqtSlot(QString, QtGui.QColor) + @QtCore.pyqtSlot(str, QtGui.QColor) def updateColorSlot(self, handle, color): PchumLog.debug("updateColorSlot(%s, %s)", handle, color) self.changeColor(handle, color) - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def deliverMessage(self, handle, msg): h = str(handle) m = str(msg) self.newMessage(h, m) - @QtCore.pyqtSlot(QString, QString, QString) + @QtCore.pyqtSlot(str, str, str) def deliverMemo(self, chan, handle, msg): (c, h, m) = (str(chan), str(handle), str(msg)) self.newMemoMsg(c, h, m) - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def deliverNotice(self, handle, msg): h = str(handle) m = str(msg) @@ -2710,7 +2708,7 @@ class PesterWindow(MovingWindow): t = self.tm.Toast("%s:" % h, m) t.show() - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def deliverInvite(self, handle, channel): msgbox = QtWidgets.QMessageBox() msgbox.setText("You're invited!") @@ -2739,25 +2737,25 @@ class PesterWindow(MovingWindow): if ret == QtWidgets.QMessageBox.StandardButton.Ok: self.newMemo(str(channel), "+0:00") - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def chanInviteOnly(self, channel): self.inviteOnlyChan.emit(channel) - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def cannotSendToChan(self, channel, msg): self.deliverMemo(channel, "ChanServ", msg) # Unused and redefined. - # @QtCore.pyqtSlot(QString, QString) + # @QtCore.pyqtSlot(str, str) # def modesUpdated(self, channel, modes): # self.modesUpdated.emit(channel, modes) - @QtCore.pyqtSlot(QString, QString, QString) + @QtCore.pyqtSlot(str, str, str) def timeCommand(self, chan, handle, command): (c, h, cmd) = (str(chan), str(handle), str(command)) if self.memos[c]: self.memos[c].timeUpdate(h, cmd) - @QtCore.pyqtSlot(QString, QString, QString) + @QtCore.pyqtSlot(str, str, str) def quirkDisable(self, channel, msg, op): (c, msg, op) = (str(channel), str(msg), str(op)) if c not in self.memos: @@ -2765,7 +2763,7 @@ class PesterWindow(MovingWindow): memo = self.memos[c] memo.quirkDisable(op, msg) - @QtCore.pyqtSlot(QString, PesterList) + @QtCore.pyqtSlot(str, PesterList) def updateNames(self, channel, names): c = str(channel) # update name DB @@ -2773,7 +2771,7 @@ class PesterWindow(MovingWindow): # warn interested party of names self.namesUpdated.emit(c) - @QtCore.pyqtSlot(QString, QString, QString) + @QtCore.pyqtSlot(str, str, str) def userPresentUpdate(self, handle, channel, update): c = str(channel) n = str(handle) @@ -2861,7 +2859,7 @@ class PesterWindow(MovingWindow): self.addChum(chum) self.addchumdialog = None - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def removeChum(self, chumlisting): self.config.removeChum(chumlisting) @@ -2874,7 +2872,7 @@ class PesterWindow(MovingWindow): if ok: self.sendMessage.emit("REPORT {} {}".format(handle, reason), "calSprite") - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def blockChum(self, handle): h = str(handle) self.config.addBlocklist(h) @@ -2897,7 +2895,7 @@ class PesterWindow(MovingWindow): if not self.config.irc_compatibility_mode(): self.blockedChum.emit(handle) - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def unblockChum(self, handle): h = str(handle) self.config.delBlocklist(h) @@ -3103,13 +3101,13 @@ class PesterWindow(MovingWindow): self.requestNames.emit("#pesterchum") self.allusers.show() - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def userListAdd(self, handle): h = str(handle) chum = PesterProfile(h, chumdb=self.chumdb) self.addChum(chum) - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def userListPester(self, handle): h = str(handle) self.newConversation(h) @@ -3724,7 +3722,7 @@ class PesterWindow(MovingWindow): ) ) - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def nickCollision(self, handle, tmphandle): if hasattr(self, "loadingscreen"): if self.loadingscreen is not None: @@ -3747,7 +3745,7 @@ class PesterWindow(MovingWindow): h = str(handle) self.changeProfile(collision=h) - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def getSvsnickedOn(self, oldhandle, newhandle): if hasattr(self, "loadingscreen"): if self.loadingscreen is not None: @@ -3765,7 +3763,7 @@ class PesterWindow(MovingWindow): if not self.chooseprofile: self.changeProfile(svsnick=(oldhandle, newhandle)) - @QtCore.pyqtSlot(QString) + @QtCore.pyqtSlot(str) def myHandleChanged(self, handle): # Update nick in channels for memo in self.memos.keys(): @@ -3800,7 +3798,7 @@ class PesterWindow(MovingWindow): # msg.setStyleSheet("QMessageBox{" + self.theme["main/defaultwindow/style"] + "}") msg.exec() - @QtCore.pyqtSlot(QString, QString) + @QtCore.pyqtSlot(str, str) def forbiddenchannel(self, channel, reason): self.forbiddenChan.emit(channel, reason) From 69f409b9d1c325a3f9b6eb8267049578af9758a5 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Sun, 19 Feb 2023 20:06:59 +0100 Subject: [PATCH 3/4] Remove most unnecessary str typecasts from pesterchum.py --- memos.py | 5 +- menus.py | 4 +- pesterchum.py | 164 +++++++++++++++++++++++--------------------------- 3 files changed, 78 insertions(+), 95 deletions(-) diff --git a/memos.py b/memos.py index 5872ca3..e612e78 100644 --- a/memos.py +++ b/memos.py @@ -31,6 +31,7 @@ _valid_memo_msg_start = re.compile( r"^([A-Z]{3}):\s" ) + def delta2txt(d, format="pc"): if isinstance(d, mysteryTime): return "?" @@ -1481,9 +1482,7 @@ class PesterMemo(PesterConvo): def closeForbidden(self, channel, reason): c = str(channel) if c.lower() == self.channel.lower(): - self.mainwindow.forbiddenChan[str, str].disconnect( - self.closeForbidden - ) + self.mainwindow.forbiddenChan[str, str].disconnect(self.closeForbidden) if self.parent(): PchumLog.info(self.channel) i = self.parent().tabIndices[self.channel] diff --git a/menus.py b/menus.py index d51dfcb..ac32eff 100644 --- a/menus.py +++ b/menus.py @@ -1846,9 +1846,7 @@ class PesterUserlist(QtWidgets.QDialog): self.mainwindow.namesUpdated.connect(self.updateUsers) - self.mainwindow.userPresentSignal[str, str, str].connect( - self.updateUserPresent - ) + self.mainwindow.userPresentSignal[str, str, str].connect(self.updateUserPresent) self.updateUsers() self.searchbox.setFocus() diff --git a/pesterchum.py b/pesterchum.py index af70252..d3c7d40 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -483,7 +483,7 @@ class chumArea(RightClickTree): def getOptionsMenu(self): if not self.currentItem(): return None - text = str(self.currentItem().text(0)) + text = self.currentItem().text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] if text == "Chums": @@ -535,11 +535,11 @@ class chumArea(RightClickTree): else: event.ignore() return - thisitem = str(event.source().currentItem().text(0)) + thisitem = event.source().currentItem().text(0) if thisitem.rfind(" (") != -1: thisitem = thisitem[0 : thisitem.rfind(" (")] # Drop item is a group - thisitem = str(event.source().currentItem().text(0)) + thisitem = event.source().currentItem().text(0) if thisitem.rfind(" (") != -1: thisitem = thisitem[0 : thisitem.rfind(" (")] if thisitem == "Chums" or thisitem in self.groups: @@ -551,7 +551,7 @@ class chumArea(RightClickTree): droppos = self.itemAt(event.pos()) if not droppos: return - droppos = str(droppos.text(0)) + droppos = droppos.text(0) if droppos.rfind(" ") != -1: droppos = droppos[0 : droppos.rfind(" ")] if droppos == "Chums" or droppos in self.groups: @@ -573,10 +573,10 @@ class chumArea(RightClickTree): gTemp = [] for i in range(self.topLevelItemCount()): - text = str(self.topLevelItem(i).text(0)) + text = self.topLevelItem(i).text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] - gTemp.append([str(text), self.topLevelItem(i).isExpanded()]) + gTemp.append([text, self.topLevelItem(i).isExpanded()]) self.mainwindow.config.saveGroups(gTemp) # Drop item is a chum else: @@ -588,7 +588,7 @@ class chumArea(RightClickTree): eventpos = event.pos() item = self.itemAt(eventpos) if item: - text = str(item.text(0)) + text = item.text(0) # Figure out which group to drop into if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] @@ -596,7 +596,7 @@ class chumArea(RightClickTree): group = text gitem = item else: - ptext = str(item.parent().text(0)) + ptext = item.parent().text(0) if ptext.rfind(" ") != -1: ptext = ptext[0 : ptext.rfind(" ")] group = ptext @@ -615,11 +615,11 @@ class chumArea(RightClickTree): chums = self.mainwindow.config.chums() if item == gitem: item = gitem.child(0) - inPos = chums.index(str(item.text(0))) + inPos = chums.index(item.text(0)) if chums.index(thisitem) < inPos: inPos -= 1 chums.remove(thisitem) - chums.insert(inPos, str(thisitem)) + chums.insert(inPos, thisitem) self.mainwindow.config.setChums(chums) else: @@ -631,9 +631,9 @@ class chumArea(RightClickTree): currentGroup = self.currentItem() if currentGroup: if currentGroup.parent(): - text = str(currentGroup.parent().text(0)) + text = currentGroup.parent().text(0) else: - text = str(currentGroup.text(0)) + text = currentGroup.text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] currentGroup = text @@ -701,7 +701,7 @@ class chumArea(RightClickTree): return curgroups = [] for i in range(self.topLevelItemCount()): - text = str(self.topLevelItem(i).text(0)) + text = self.topLevelItem(i).text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] curgroups.append(text) @@ -726,24 +726,24 @@ class chumArea(RightClickTree): totals = {"Chums": 0} online = {"Chums": 0} for g in self.groups: - totals[str(g)] = 0 - online[str(g)] = 0 + totals[g] = 0 + online[g] = 0 for c in self.chums: yes = c.mood.name() != "offline" if c.group == "Chums": - totals[str(c.group)] = totals[str(c.group)] + 1 + totals[c.group] = totals[c.group] + 1 if yes: - online[str(c.group)] = online[str(c.group)] + 1 + online[c.group] = online[c.group] + 1 elif c.group in totals: - totals[str(c.group)] = totals[str(c.group)] + 1 + totals[c.group] = totals[c.group] + 1 if yes: - online[str(c.group)] = online[str(c.group)] + 1 + online[c.group] = online[c.group] + 1 else: totals["Chums"] = totals["Chums"] + 1 if yes: online["Chums"] = online["Chums"] + 1 for i in range(self.topLevelItemCount()): - text = str(self.topLevelItem(i).text(0)) + text = self.topLevelItem(i).text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] if text in online: @@ -753,7 +753,7 @@ class chumArea(RightClickTree): def hideOnlineNumbers(self): for i in range(self.topLevelItemCount()): - text = str(self.topLevelItem(i).text(0)) + text = self.topLevelItem(i).text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] self.topLevelItem(i).setText(0, "%s" % (text)) @@ -771,7 +771,7 @@ class chumArea(RightClickTree): @QtCore.pyqtSlot() def expandGroup(self): item = self.currentItem() - text = str(item.text(0)) + text = item.text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] @@ -787,7 +787,7 @@ class chumArea(RightClickTree): self.mainwindow.config.addGroup("Chums") curgroups = [] for i in range(self.topLevelItemCount()): - text = str(self.topLevelItem(i).text(0)) + text = self.topLevelItem(i).text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] curgroups.append(text) @@ -810,7 +810,7 @@ class chumArea(RightClickTree): ]: child_1.setExpanded(True) for i in range(self.topLevelItemCount()): - text = str(self.topLevelItem(i).text(0)) + text = self.topLevelItem(i).text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] if text == chumLabel.chum.group: @@ -830,7 +830,7 @@ class chumArea(RightClickTree): if fi > 0: while not bestj: for j in range(self.topLevelItem(i).childCount()): - if chums[fi - c] == str( + if chums[fi - c] == ( self.topLevelItem(i).child(j).text(0) ): bestj = j @@ -1063,7 +1063,6 @@ class chumArea(RightClickTree): self, "Notes", "Enter your notes..." ) if ok: - notes = str(notes) self.mainwindow.chumdb.setNotes(currentChum.handle, notes) currentChum.setToolTip(0, "{}: {}".format(currentChum.handle, notes)) @@ -1076,7 +1075,6 @@ class chumArea(RightClickTree): self, "Rename Group", "Enter a new name for the group:" ) if ok: - gname = str(gname) if re.search(r"[^A-Za-z0-9_\s]", gname) is not None: msgbox = QtWidgets.QMessageBox() msgbox.setStyleSheet( @@ -1094,7 +1092,7 @@ class chumArea(RightClickTree): index = self.indexOfTopLevelItem(currentGroup) if index != -1: expanded = currentGroup.isExpanded() - text = str(currentGroup.text(0)) + text = currentGroup.text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] self.mainwindow.config.delGroup(text) @@ -1117,7 +1115,7 @@ class chumArea(RightClickTree): currentGroup = self.currentItem() if not currentGroup: return - text = str(currentGroup.text(0)) + text = currentGroup.text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] self.mainwindow.config.delGroup(text) @@ -1141,7 +1139,7 @@ class chumArea(RightClickTree): def moveToGroup(self, item): if not item: return - group = str(item.text()) + group = item.text() chumLabel = self.currentItem() if not chumLabel: return @@ -1280,7 +1278,6 @@ class TrollSlumWindow(QtWidgets.QFrame): self, "Add Troll", "Enter Troll Handle:" ) if ok: - handle = str(handle) if not ( PesterProfile.checkLength(handle) and PesterProfile.checkValid(handle)[0] @@ -2025,15 +2022,16 @@ class PesterWindow(MovingWindow): self.tabconvo.show() else: convoWindow = PesterConvo(chum, initiated, self) - convoWindow.messageSent[str, str].connect( - self.sendMessage[str, str] - ) + convoWindow.messageSent[str, str].connect(self.sendMessage[str, str]) convoWindow.windowClosed[str].connect(self.closeConvo) self.convos[chum.handle] = convoWindow if chum.handle.upper() in BOTNAMES: convoWindow.toggleQuirks(True) convoWindow.quirksOff.setChecked(True) - if not self.config.irc_compatibility_mode() or chum.handle.upper() in CUSTOMBOTS: + if ( + not self.config.irc_compatibility_mode() + or chum.handle.upper() in CUSTOMBOTS + ): self.newConvoStarted.emit(chum.handle, initiated) else: self.newConvoStarted.emit(chum.handle, initiated) @@ -2134,15 +2132,11 @@ class PesterWindow(MovingWindow): # connect signals self.inviteOnlyChan[str].connect(memoWindow.closeInviteOnly) self.forbiddenChan[str, str].connect(memoWindow.closeForbidden) - memoWindow.messageSent[str, str].connect( - self.sendMessage[str, str] - ) + memoWindow.messageSent[str, str].connect(self.sendMessage[str, str]) memoWindow.windowClosed[str].connect(self.closeMemo) self.namesUpdated[str].connect(memoWindow.namesUpdated) self.modesUpdated[str, str].connect(memoWindow.modesUpdated) - self.userPresentSignal[str, str, str].connect( - memoWindow.userPresentChange - ) + self.userPresentSignal[str, str, str].connect(memoWindow.userPresentChange) # chat client send memo open self.memos[channel] = memoWindow self.joinChannel.emit(channel) # race condition? @@ -2591,7 +2585,7 @@ class PesterWindow(MovingWindow): def pesterSelectedChum(self): curChum = self.chumList.currentItem() if curChum: - text = str(curChum.text(0)) + text = curChum.text(0) if text.rfind(" (") != -1: text = text[0 : text.rfind(" (")] if text not in self.chumList.groups and text != "Chums": @@ -2608,7 +2602,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str) def closeConvo(self, handle): - h = str(handle) + h = handle try: chum = self.convos[h].chum except KeyError: @@ -2633,7 +2627,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str) def closeMemo(self, channel): - c = str(channel) + c = channel self.chatlog.finish(c) self.leftChannel.emit(channel) try: @@ -2656,7 +2650,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str, Mood) def updateMoodSlot(self, handle, mood): - h = str(handle) + h = handle self.updateMood(h, mood) @QtCore.pyqtSlot(str, QtGui.QColor) @@ -2666,19 +2660,18 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str, str) def deliverMessage(self, handle, msg): - h = str(handle) - m = str(msg) + h = handle + m = msg self.newMessage(h, m) @QtCore.pyqtSlot(str, str, str) def deliverMemo(self, chan, handle, msg): - (c, h, m) = (str(chan), str(handle), str(msg)) - self.newMemoMsg(c, h, m) + self.newMemoMsg(chan, handle, msg) @QtCore.pyqtSlot(str, str) def deliverNotice(self, handle, msg): - h = str(handle) - m = str(msg) + h = handle + m = msg if h.upper() == "NICKSERV" and m.startswith( "Your nickname is now being changed to" ): @@ -2751,30 +2744,27 @@ class PesterWindow(MovingWindow): # self.modesUpdated.emit(channel, modes) @QtCore.pyqtSlot(str, str, str) def timeCommand(self, chan, handle, command): - (c, h, cmd) = (str(chan), str(handle), str(command)) - if self.memos[c]: - self.memos[c].timeUpdate(h, cmd) + if self.memos[chan]: + self.memos[chan].timeUpdate(handle, command) @QtCore.pyqtSlot(str, str, str) def quirkDisable(self, channel, msg, op): - (c, msg, op) = (str(channel), str(msg), str(op)) - if c not in self.memos: + if channel not in self.memos: return - memo = self.memos[c] + memo = self.memos[channel] memo.quirkDisable(op, msg) @QtCore.pyqtSlot(str, PesterList) def updateNames(self, channel, names): - c = str(channel) # update name DB - self.namesdb[c] = names + self.namesdb[channel] = names # warn interested party of names - self.namesUpdated.emit(c) + self.namesUpdated.emit(channel) @QtCore.pyqtSlot(str, str, str) def userPresentUpdate(self, handle, channel, update): - c = str(channel) - n = str(handle) + c = channel + n = handle # print("c=%s\nn=%s\nupdate=%s\n" % (c, n, update)) if update == "nick": l = n.split(":") @@ -2829,12 +2819,11 @@ class PesterWindow(MovingWindow): available_groups = [g[0] for g in self.config.getGroups()] self.addchumdialog = AddChumDialog(available_groups, self) ok = self.addchumdialog.exec() - handle = str(self.addchumdialog.chumBox.text()).strip() - newgroup = str(self.addchumdialog.newgroup.text()).strip() + handle = (self.addchumdialog.chumBox.text()).strip() + newgroup = (self.addchumdialog.newgroup.text()).strip() selectedGroup = self.addchumdialog.groupBox.currentText() group = newgroup if newgroup else selectedGroup if ok: - handle = str(handle) if handle in [h.handle for h in self.chumList.chums]: self.addchumdialog = None return @@ -2874,7 +2863,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str) def blockChum(self, handle): - h = str(handle) + h = handle self.config.addBlocklist(h) self.config.removeChum(h) if h in self.convos: @@ -2897,7 +2886,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str) def unblockChum(self, handle): - h = str(handle) + h = handle self.config.delBlocklist(h) if h in self.convos: convo = self.convos[h] @@ -3054,25 +3043,25 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot() def joinSelectedMemo(self): - time = str(self.memochooser.timeinput.text()) + time = self.memochooser.timeinput.text() secret = self.memochooser.secretChannel.isChecked() invite = self.memochooser.inviteChannel.isChecked() # Join the ones on the list first for SelectedMemo in self.memochooser.SelectedMemos(): - channel = "#" + str(SelectedMemo.target) + channel = f"#{SelectedMemo.target}" self.newMemo(channel, time) if self.memochooser.newmemoname(): newmemo = self.memochooser.newmemoname() - channel = str(newmemo).replace(" ", "_") + channel = newmemo.replace(" ", "_") channel = re.sub(r"[^A-Za-z0-9#_\,]", "", channel) # Allow us to join more than one with this. chans = channel.split(",") # Filter out empty entries. chans = [_f for _f in chans if _f] for c in chans: - c = "#" + c + c = f"#{c}" # We should really change this code to only make the memo once # the server has confirmed that we've joined.... self.newMemo(c, time, secret=secret, invite=invite) @@ -3103,14 +3092,12 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(str) def userListAdd(self, handle): - h = str(handle) - chum = PesterProfile(h, chumdb=self.chumdb) + chum = PesterProfile(handle, chumdb=self.chumdb) self.addChum(chum) @QtCore.pyqtSlot(str) def userListPester(self, handle): - h = str(handle) - self.newConversation(h) + self.newConversation(handle) @QtCore.pyqtSlot() def userListClose(self): @@ -3131,7 +3118,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot() def updateQuirks(self): for i in range(self.quirkmenu.quirkList.topLevelItemCount()): - curgroup = str(self.quirkmenu.quirkList.topLevelItem(i).text(0)) + curgroup = self.quirkmenu.quirkList.topLevelItem(i).text(0) for j in range(self.quirkmenu.quirkList.topLevelItem(i).childCount()): item = self.quirkmenu.quirkList.topLevelItem(i).child(j) item.quirk.quirk["on"] = item.quirk.on = ( @@ -3160,7 +3147,7 @@ class PesterWindow(MovingWindow): ) try: if ok: - self.newConversation(str(chum)) + self.newConversation(chum) except: pass finally: @@ -3192,7 +3179,6 @@ class PesterWindow(MovingWindow): self, "Add Group", "Enter a name for the new group:" ) if ok: - gname = str(gname) if re.search(r"[^A-Za-z0-9_\s]", gname) is not None: msgbox = QtWidgets.QMessageBox() msgbox.setInformativeText("THIS IS NOT A VALID GROUP NAME") @@ -3333,7 +3319,7 @@ class PesterWindow(MovingWindow): # timestamps timestampsetting = self.optionmenu.timestampcheck.isChecked() self.config.set("showTimeStamps", timestampsetting) - timeformatsetting = str(self.optionmenu.timestampBox.currentText()) + timeformatsetting = self.optionmenu.timestampBox.currentText() if timeformatsetting == "12 hour": self.config.set("time12Format", True) else: @@ -3443,7 +3429,7 @@ class PesterWindow(MovingWindow): self.config.set("blink", blinksetting) # toast notifications self.tm.setEnabled(self.optionmenu.notifycheck.isChecked()) - self.tm.setCurrentType(str(self.optionmenu.notifyOptions.currentText())) + self.tm.setCurrentType(self.optionmenu.notifyOptions.currentText()) notifysetting = 0 if self.optionmenu.notifySigninCheck.isChecked(): notifysetting |= self.config.SIGNIN @@ -3476,11 +3462,11 @@ class PesterWindow(MovingWindow): autoidentify = self.optionmenu.autonickserv.isChecked() nickservpass = self.optionmenu.nickservpass.text() self.userprofile.setAutoIdentify(autoidentify) - self.userprofile.setNickServPass(str(nickservpass)) + self.userprofile.setNickServPass(nickservpass) # auto join memos autojoins = [] for i in range(self.optionmenu.autojoinlist.count()): - autojoins.append(str(self.optionmenu.autojoinlist.item(i).text())) + autojoins.append(self.optionmenu.autojoinlist.item(i).text()) self.userprofile.setAutoJoins(autojoins) # advanced ## user mode @@ -3515,7 +3501,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot() def themeSelected(self, override=False): if not override: - themename = str(self.optionmenu.themeBox.currentText()) + themename = self.optionmenu.themeBox.currentText() else: themename = override if override or themename != self.theme.name: @@ -3541,7 +3527,7 @@ class PesterWindow(MovingWindow): self.chooseprofile.profileBox and self.chooseprofile.profileBox.currentIndex() > 0 ): - handle = str(self.chooseprofile.profileBox.currentText()) + handle = self.chooseprofile.profileBox.currentText() if handle == self.profile().handle: self.chooseprofile = None return @@ -3584,7 +3570,7 @@ class PesterWindow(MovingWindow): msgBox.exec() return else: - handle = str(self.chooseprofile.chumHandle.text()) + handle = self.chooseprofile.chumHandle.text() if handle == self.profile().handle: self.chooseprofile = None return @@ -3742,7 +3728,7 @@ class PesterWindow(MovingWindow): if not hasattr(self, "chooseprofile"): self.chooseprofile = None if not self.chooseprofile: - h = str(handle) + h = handle self.changeProfile(collision=h) @QtCore.pyqtSlot(str, str) @@ -4605,7 +4591,7 @@ class MainProgram(QtCore.QObject): traceback.print_tb(tb, file=f) f.close() except Exception as e: - print(str(e)) + print(e) # Show msgbox msgbox = QtWidgets.QMessageBox() @@ -4615,7 +4601,7 @@ class MainProgram(QtCore.QObject): "QMessageBox{" + self.widget.theme["main/defaultwindow/style"] + "}" ) except Exception as e: - print(str(e)) + print(e) msgbox.setStyleSheet( "background-color: red; color: black; font-size: x-large;" ) @@ -4625,7 +4611,7 @@ class MainProgram(QtCore.QObject): ) msgbox.exec() except Exception as e: - print("failed to process uncaught except: " + str(e)) + print(f"Failed to process uncaught except: {e}") PchumLog.exception("app error") def run(self): From 2398b5a6262f6e5595e4ebfa17c7a8748c8865d5 Mon Sep 17 00:00:00 2001 From: Dpeta <69427753+Dpeta@users.noreply.github.com> Date: Sun, 19 Feb 2023 21:10:35 +0100 Subject: [PATCH 4/4] Remove most unnecessary str() typecasts. --- convo.py | 25 +++++++++--------- dataobjs.py | 8 +++--- generic.py | 6 ++--- irc.py | 2 +- logviewer.py | 11 +++----- memos.py | 50 +++++++++++++++-------------------- menus.py | 70 +++++++++++++++++++++++-------------------------- parsetools.py | 19 ++++++-------- pytwmn.py | 18 ++++++------- randomer.py | 2 +- toast.py | 4 +-- user_profile.py | 2 +- 12 files changed, 99 insertions(+), 118 deletions(-) diff --git a/convo.py b/convo.py index 2ee33dc..c2879f1 100644 --- a/convo.py +++ b/convo.py @@ -218,7 +218,7 @@ class PesterTabWindow(QtWidgets.QFrame): i = self.tabs.tabAt(self.mapFromGlobal(QtGui.QCursor.pos())) if i == -1: i = self.tabs.currentIndex() - handle = str(self.tabs.tabText(i)) + handle = self.tabs.tabText(i) self.clearNewMessage(handle) def convoHasFocus(self, handle): @@ -267,13 +267,13 @@ class PesterTabWindow(QtWidgets.QFrame): self.tabs.setTabIcon(tabi, c.icon()) currenttabi = self.tabs.currentIndex() if currenttabi >= 0: - currentHandle = str(self.tabs.tabText(self.tabs.currentIndex())) + currentHandle = self.tabs.tabText(self.tabs.currentIndex()) self.setWindowIcon(self.convos[currentHandle].icon()) self.defaultTabTextColor = self.getTabTextColor() @QtCore.pyqtSlot(int) def tabClose(self, i): - handle = str(self.tabs.tabText(i)) + handle = self.tabs.tabText(i) self.mainwindow.waitingMessages.messageAnswered(handle) # print(self.convos.keys()) # I, legit don' t know why this is an issue, but, uh, yeah- @@ -296,7 +296,7 @@ class PesterTabWindow(QtWidgets.QFrame): return if self.currentConvo == convo: currenti = self.tabs.currentIndex() - currenth = str(self.tabs.tabText(currenti)) + currenth = self.tabs.tabText(currenti) self.currentConvo = self.convos[currenth] self.currentConvo.raiseChat() @@ -307,7 +307,7 @@ class PesterTabWindow(QtWidgets.QFrame): if self.changedTab: self.changedTab = False return - handle = str(self.tabs.tabText(i)) + handle = self.tabs.tabText(i) convo = self.convos[handle] if self.currentConvo: self.layout.removeWidget(self.currentConvo) @@ -344,7 +344,7 @@ class PesterMovie(QtGui.QMovie): if text.mainwindow.config.animations(): movie = self url = text.urls[movie].toString() - html = str(text.toHtml()) + html = text.toHtml() if html.find(url) != -1: try: # PyQt6 @@ -606,7 +606,7 @@ class PesterText(QtWidgets.QTextEdit): if url[0] == "#" and url != "#pesterchum": self.parent().mainwindow.showMemos(url[1:]) elif url[0] == "@": - handle = str(url[1:]) + handle = url[1:] self.parent().mainwindow.newConversation(handle) else: if event.modifiers() == QtCore.Qt.KeyboardModifier.ControlModifier: @@ -664,7 +664,7 @@ class PesterInput(QtWidgets.QLineEdit): def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key.Key_Up: - text = str(self.text()) + text = self.text() next = self.parent().history.next(text) if next is not None: self.setText(next) @@ -1091,14 +1091,13 @@ class PesterConvo(QtWidgets.QFrame): @QtCore.pyqtSlot() def sentMessage(self): - # Offloaded to another function, like its sisters. - # Fetch the raw text from the input box. - text = self.textInput.text() - text = str(self.textInput.text()) + """Offloaded to another function, like its sisters. + Fetch the raw text from the input box. + """ return parsetools.kxhandleInput( self, - text, + self.textInput.text(), flavor="convo", irc_compatible=self.mainwindow.config.irc_compatibility_mode(), ) diff --git a/dataobjs.py b/dataobjs.py index ef0c5b4..721ee5e 100644 --- a/dataobjs.py +++ b/dataobjs.py @@ -147,7 +147,7 @@ class pesterQuirks: newlist = [] for i, o in enumerate(lexed): - if type(o) not in [str, str]: + if not isinstance(o, str): if i == 0: string = " " for p in prefix: @@ -250,7 +250,7 @@ class pesterQuirks: newlist.append(string) final = [] for n in newlist: - if type(n) in [str, str]: + if isinstance(n, str): final.extend(lexMessage(n)) else: final.append(n) @@ -456,7 +456,7 @@ class PesterProfile: opinit, self.colorhtml(), ", ".join(initials), - str(reason), + reason, ) ) else: @@ -477,7 +477,7 @@ class PesterProfile: opinit, self.colorhtml(), initials, - str(reason), + reason, ) ) diff --git a/generic.py b/generic.py index a013854..99316a4 100644 --- a/generic.py +++ b/generic.py @@ -39,7 +39,7 @@ class PesterList(list): class PesterIcon(QtGui.QIcon): def __init__(self, *x): super().__init__(x[0]) - if type(x[0]) in [str, str]: + if isinstance(x[0], str): self.icon_pixmap = QtGui.QPixmap(x[0]) else: self.icon_pixmap = None @@ -117,7 +117,7 @@ class MultiTextDialog(QtWidgets.QDialog): if r == QtWidgets.QDialog.DialogCode.Accepted: retval = {} for name, widget in self.inputs.items(): - retval[name] = str(widget.text()) + retval[name] = widget.text() return retval else: return None @@ -150,7 +150,7 @@ class MovingWindow(QtWidgets.QFrame): self.moving = event.globalPos() - self.pos() except AttributeError as e: print("PyQt <= 5.14?") - print(str(e)) + print(e) if event.button() == 1: self.moving = event.globalPos() - self.pos() diff --git a/irc.py b/irc.py index 371c327..948c2ee 100644 --- a/irc.py +++ b/irc.py @@ -437,7 +437,7 @@ class PesterIRC(QtCore.QThread): """Update and send color, slot is called from main thread.""" # Update color metadata field color = self.mainwindow.profile().color - self._send_irc.metadata("*", "set", "color", str(color.name())) + self._send_irc.metadata("*", "set", "color", color.name()) # Send color messages for convo in list(self.mainwindow.convos.keys()): self._send_irc.privmsg( diff --git a/logviewer.py b/logviewer.py index b3eb669..d6773af 100644 --- a/logviewer.py +++ b/logviewer.py @@ -42,10 +42,7 @@ class PesterLogHighlighter(QtGui.QSyntaxHighlighter): def highlightBlock(self, text): for i in range(0, len(text) - (len(self.searchTerm) - 1)): - if ( - str(text[i : i + len(self.searchTerm)]).lower() - == str(self.searchTerm).lower() - ): + if text[i : i + len(self.searchTerm)].lower() == self.searchTerm.lower(): self.setFormat(i, len(self.searchTerm), self.hilightstyle) @@ -297,7 +294,7 @@ class PesterLogViewer(QtWidgets.QDialog): if len(self.tree.currentItem().text(0)) > len("September 2011"): self.loadLog(self.timeToFile(self.tree.currentItem().text(0))) - def loadLog(self, fname): + def loadLog(self, fname: str): fp = codecs.open( "%s/%s/%s/%s/%s" % (self.logpath, self.handle, self.chum, self.format, fname), @@ -318,7 +315,7 @@ class PesterLogViewer(QtWidgets.QDialog): # textCur.movePosition(1) self.textArea.setTextCursor(textCur) self.instructions.setText( - "Pesterlog with " + self.chum + " on " + self.fileToTime(str(fname)) + "Pesterlog with " + self.chum + " on " + self.fileToTime(fname) ) def logSearch(self, search): @@ -359,7 +356,7 @@ class PesterLogText(PesterText): if url[0] == "#" and url != "#pesterchum": self.parent().parent.showMemos(url[1:]) elif url[0] == "@": - handle = str(url[1:]) + handle = url[1:] self.parent().parent.newConversation(handle) else: QtGui.QDesktopServices.openUrl( diff --git a/memos.py b/memos.py index e612e78..39f8f75 100644 --- a/memos.py +++ b/memos.py @@ -240,7 +240,7 @@ class TimeInput(QtWidgets.QLineEdit): @QtCore.pyqtSlot() def setSlider(self): - value = str(self.text()) + value = self.text() timed = txt2delta(value) if isinstance(timed, mysteryTime): self.timeslider.setValue(0) @@ -1008,10 +1008,9 @@ class PesterMemo(PesterConvo): PchumLog.debug("updateChanModes(%s, %s)", modes, op) if not hasattr(self, "modes"): self.modes = "" - chanmodes = list(str(self.modes)) + chanmodes = list((self.modes)) if chanmodes and chanmodes[0] == "+": chanmodes = chanmodes[1:] - modes = str(modes) if op: systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"]) chum = self.mainwindow.profile() @@ -1428,7 +1427,7 @@ class PesterMemo(PesterConvo): @QtCore.pyqtSlot() def sentMessage(self): - text = str(self.textInput.text()) + text = self.textInput.text() return parsetools.kxhandleInput( self, @@ -1439,8 +1438,7 @@ class PesterMemo(PesterConvo): @QtCore.pyqtSlot(str) def namesUpdated(self, channel): - c = str(channel) - if c.lower() != self.channel.lower(): + if channel.lower() != self.channel.lower(): return # get namesdb (unused) # namesdb = self.mainwindow.namesdb @@ -1457,8 +1455,7 @@ class PesterMemo(PesterConvo): @QtCore.pyqtSlot(str) def closeInviteOnly(self, channel): - c = str(channel) - if c.lower() == self.channel.lower(): + if channel.lower() == self.channel.lower(): self.mainwindow.inviteOnlyChan[str].disconnect(self.closeInviteOnly) if self.parent(): PchumLog.info(self.channel) @@ -1470,7 +1467,7 @@ class PesterMemo(PesterConvo): msgbox.setStyleSheet( "QMessageBox{ %s }" % self.mainwindow.theme["main/defaultwindow/style"] ) - msgbox.setText("%s: Invites only!" % (c)) + msgbox.setText(f"{channel}: Invites only!") msgbox.setInformativeText( "This channel is invite-only. " "You must get an invitation from someone on the inside before entering." @@ -1480,8 +1477,7 @@ class PesterMemo(PesterConvo): @QtCore.pyqtSlot(str, str) def closeForbidden(self, channel, reason): - c = str(channel) - if c.lower() == self.channel.lower(): + if channel.lower() == self.channel.lower(): self.mainwindow.forbiddenChan[str, str].disconnect(self.closeForbidden) if self.parent(): PchumLog.info(self.channel) @@ -1493,7 +1489,7 @@ class PesterMemo(PesterConvo): msgbox.setStyleSheet( "QMessageBox{ %s }" % self.mainwindow.theme["main/defaultwindow/style"] ) - msgbox.setText("%s: D: CANT JOIN MEMO!!!" % (c)) + msgbox.setText(f"{channel}: D: CANT JOIN MEMO!!!") msgbox.setInformativeText(reason) msgbox.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Ok) msgbox.exec() @@ -1568,12 +1564,9 @@ class PesterMemo(PesterConvo): del self.netsplit @QtCore.pyqtSlot(str, str, str) - def userPresentChange(self, handle, channel, update): - # print("handle: %s, channel: %s, update: %s" % (handle, channel, update)) - h = str(handle) - c = str(channel) - update = str(update) - # PchumLog.debug("h=%s\nc=%s\nupdate=%s" % (h,c,update)) + def userPresentChange(self, handle: str, channel: str, update: str): + h = handle + c = channel if update[0:4] == "kick": # yeah, i'm lazy. l = update.split(":") update = l[0] @@ -1790,7 +1783,7 @@ class PesterMemo(PesterConvo): for c in chums: c.op = True self.iconCrap(c) - if str(c.text()) == self.mainwindow.profile().handle: + if (c.text()) == self.mainwindow.profile().handle: self.userlist.optionsMenu.addAction(self.opAction) self.userlist.optionsMenu.addAction(self.voiceAction) self.userlist.optionsMenu.addAction(self.banuserAction) @@ -1807,7 +1800,7 @@ class PesterMemo(PesterConvo): for c in chums: c.op = False self.iconCrap(c) - if str(c.text()) == self.mainwindow.profile().handle: + if (c.text()) == self.mainwindow.profile().handle: self.userlist.optionsMenu.removeAction(self.opAction) self.userlist.optionsMenu.removeAction(self.voiceAction) self.userlist.optionsMenu.removeAction(self.banuserAction) @@ -1823,7 +1816,7 @@ class PesterMemo(PesterConvo): for c in chums: c.halfop = True self.iconCrap(c) - if str(c.text()) == self.mainwindow.profile().handle: + if (c.text()) == self.mainwindow.profile().handle: self.userlist.optionsMenu.addAction(self.opAction) self.userlist.optionsMenu.addAction(self.voiceAction) self.userlist.optionsMenu.addAction(self.banuserAction) @@ -1840,7 +1833,7 @@ class PesterMemo(PesterConvo): for c in chums: c.halfop = False self.iconCrap(c) - if str(c.text()) == self.mainwindow.profile().handle: + if (c.text()) == self.mainwindow.profile().handle: self.userlist.optionsMenu.removeAction(self.opAction) self.userlist.optionsMenu.removeAction(self.voiceAction) self.userlist.optionsMenu.removeAction(self.banuserAction) @@ -1888,21 +1881,21 @@ class PesterMemo(PesterConvo): user = self.userlist.currentItem() if not user: return - user = str(user.text()) + user = user.text() self.mainwindow.newConversation(user) @QtCore.pyqtSlot() def addChumSlot(self): if not self.userlist.currentItem(): return - currentChum = PesterProfile(str(self.userlist.currentItem().text())) + currentChum = PesterProfile((self.userlist.currentItem().text())) self.mainwindow.addChum(currentChum) @QtCore.pyqtSlot() def banSelectedUser(self): if not self.userlist.currentItem(): return - currentHandle = str(self.userlist.currentItem().text()) + currentHandle = self.userlist.currentItem().text() (reason, ok) = QtWidgets.QInputDialog.getText( self, "Ban User", "Enter the reason you are banning this user (optional):" ) @@ -1913,21 +1906,21 @@ class PesterMemo(PesterConvo): def opSelectedUser(self): if not self.userlist.currentItem(): return - currentHandle = str(self.userlist.currentItem().text()) + currentHandle = self.userlist.currentItem().text() self.mainwindow.setChannelMode.emit(self.channel, "+o", currentHandle) @QtCore.pyqtSlot() def voiceSelectedUser(self): if not self.userlist.currentItem(): return - currentHandle = str(self.userlist.currentItem().text()) + currentHandle = self.userlist.currentItem().text() self.mainwindow.setChannelMode.emit(self.channel, "+v", currentHandle) @QtCore.pyqtSlot() def killQuirkUser(self): if not self.userlist.currentItem(): return - currentHandle = str(self.userlist.currentItem().text()) + currentHandle = self.userlist.currentItem().text() self.mainwindow.killSomeQuirks.emit(self.channel, currentHandle) def resetSlider(self, time, send=True): @@ -1960,7 +1953,6 @@ class PesterMemo(PesterConvo): "Enter the chumhandle of the user you'd like to invite:", ) if ok: - chum = str(chum) self.mainwindow.inviteChum.emit(chum, self.channel) self.invitechums = None diff --git a/menus.py b/menus.py index ac32eff..c19cc3c 100644 --- a/menus.py +++ b/menus.py @@ -29,7 +29,7 @@ class PesterQuirkItem(QtWidgets.QTreeWidgetItem): parent = None QtWidgets.QTreeWidgetItem.__init__(self, parent) self.quirk = quirk - self.setText(0, str(quirk)) + self.setText(0, str(quirk)) # Typecast required. def update(self, quirk): self.quirk = quirk @@ -235,7 +235,6 @@ class PesterQuirkList(QtWidgets.QTreeWidget): self, "Add Group", "Enter a name for the new quirk group:" ) if ok: - gname = str(gname) if re.search(r"[^A-Za-z0-9_\s]", gname) is not None: msgbox = QtWidgets.QMessageBox() msgbox.setInformativeText("THIS IS NOT A VALID GROUP NAME") @@ -323,7 +322,7 @@ class QuirkTesterWindow(QtWidgets.QDialog): @QtCore.pyqtSlot() def sentMessage(self): - text = str(self.textInput.text()) + text = self.textInput.text() return parsetools.kxhandleInput( self, @@ -596,8 +595,8 @@ class PesterQuirkTypes(QtWidgets.QDialog): page.itemAt(3).layout().itemAt(0).widget().setCheckState( QtCore.Qt.CheckState(int(q["checkstate"])) ) - except (KeyError, ValueError) as e: - print("KeyError: %s" % str(e)) + except (KeyError, ValueError): + PchumLog.exception("Exception setting replace quirk.") elif q["type"] == "regexp": page.itemAt(2).layout().itemAt(1).layout().itemAt(1).widget().setText( q["from"] @@ -609,8 +608,8 @@ class PesterQuirkTypes(QtWidgets.QDialog): page.itemAt(2).layout().itemAt(3).layout().itemAt( 0 ).widget().setCheckState(QtCore.Qt.CheckState(int(q["checkstate"]))) - except (KeyError, ValueError) as e: - print("KeyError: %s" % str(e)) + except (KeyError, ValueError): + PchumLog.exception("Exception setting regexp quirk.") elif q["type"] == "random": self.regexp.setText(q["from"]) for v in q["randomlist"]: @@ -619,8 +618,8 @@ class PesterQuirkTypes(QtWidgets.QDialog): page.itemAt(2).layout().itemAt(2).layout().itemAt( 0 ).widget().setCheckState(QtCore.Qt.CheckState(int(q["checkstate"]))) - except (KeyError, ValueError) as e: - print("KeyError: %s" % str(e)) + except (KeyError, ValueError): + PchumLog.exception("Exception setting random quirk.") elif q["type"] == "spelling": self.slider.setValue(q["percentage"]) try: @@ -628,7 +627,7 @@ class PesterQuirkTypes(QtWidgets.QDialog): QtCore.Qt.CheckState(int(q["checkstate"])) ) except (KeyError, ValueError) as e: - print("KeyError: %s" % str(e)) + PchumLog.exception("Exception setting spelling quirk.") self.setLayout(layout_0) @@ -667,11 +666,11 @@ class PesterQuirkTypes(QtWidgets.QDialog): @QtCore.pyqtSlot(int) def printValue(self, value): - self.current.setText(str(value) + "%") + self.current.setText(f"{value}%") @QtCore.pyqtSlot() def addRandomString(self): - text = str(self.replaceinput.text()) + text = self.replaceinput.text() item = QtWidgets.QListWidgetItem(text, self.replacelist) self.replaceinput.setText("") self.replaceinput.setFocus() @@ -815,10 +814,10 @@ class PesterChooseQuirks(QtWidgets.QDialog): vdict["type"] = types[self.quirkadd.pages.currentIndex() - 1] page = self.quirkadd.pages.currentWidget().layout() if vdict["type"] in ("prefix", "suffix"): - vdict["value"] = str(page.itemAt(1).layout().itemAt(1).widget().text()) + vdict["value"] = page.itemAt(1).layout().itemAt(1).widget().text() elif vdict["type"] == "replace": - vdict["from"] = str(page.itemAt(1).layout().itemAt(1).widget().text()) - vdict["to"] = str(page.itemAt(2).layout().itemAt(1).widget().text()) + vdict["from"] = page.itemAt(1).layout().itemAt(1).widget().text() + vdict["to"] = page.itemAt(2).layout().itemAt(1).widget().text() try: # PyQt6 vdict["checkstate"] = str( @@ -830,10 +829,10 @@ class PesterChooseQuirks(QtWidgets.QDialog): page.itemAt(3).layout().itemAt(0).widget().checkState() ) elif vdict["type"] == "regexp": - vdict["from"] = str( + vdict["from"] = ( page.itemAt(2).layout().itemAt(1).layout().itemAt(1).widget().text() ) - vdict["to"] = str( + vdict["to"] = ( page.itemAt(2).layout().itemAt(2).layout().itemAt(1).widget().text() ) try: @@ -1069,7 +1068,7 @@ class PesterChooseProfile(QtWidgets.QDialog): @QtCore.pyqtSlot() def validateProfile(self): if not self.profileBox or self.profileBox.currentIndex() == 0: - handle = str(self.chumHandle.text()) + handle = self.chumHandle.text() if not PesterProfile.checkLength(handle): self.errorMsg.setText("PROFILE HANDLE IS TOO LONG") return @@ -1084,7 +1083,7 @@ class PesterChooseProfile(QtWidgets.QDialog): @QtCore.pyqtSlot() def deleteProfile(self): if self.profileBox and self.profileBox.currentIndex() > 0: - handle = str(self.profileBox.currentText()) + handle = self.profileBox.currentText() if handle == self.parent.profile().handle: problem = QtWidgets.QMessageBox() # karxi Will probably change this to its own name later. @@ -1175,7 +1174,7 @@ class PesterMentions(QtWidgets.QDialog): def addMention(self, mitem=None): d = {"label": "Mention:", "inputname": "value"} if mitem is not None: - d["value"] = str(mitem.text()) + d["value"] = mitem.text() pdict = MultiTextDialog("ENTER MENTION", self, d).getText() if pdict is None: return @@ -1730,7 +1729,7 @@ class PesterOptions(QtWidgets.QDialog): def addAutoJoin(self, mitem=None): d = {"label": "Memo:", "inputname": "value"} if mitem is not None: - d["value"] = str(mitem.text()) + d["value"] = mitem.text() pdict = MultiTextDialog("ENTER MEMO", self, d).getText() if pdict is None: return @@ -1773,7 +1772,7 @@ class PesterOptions(QtWidgets.QDialog): @QtCore.pyqtSlot(int) def printValue(self, v): - self.currentVol.setText(str(v) + "%") + self.currentVol.setText(f"{v}%") @QtCore.pyqtSlot() def openMentions(self): @@ -1796,7 +1795,7 @@ class PesterOptions(QtWidgets.QDialog): def updateMentions(self): m = [] for i in range(self.mentionmenu.mentionlist.count()): - m.append(str(self.mentionmenu.mentionlist.item(i).text())) + m.append((self.mentionmenu.mentionlist.item(i).text())) self.parent().userprofile.setMentions(m) self.mentionmenu = None @@ -1860,10 +1859,9 @@ class PesterUserlist(QtWidgets.QDialog): return self.userarea.clear() for n in names: - if ( - str(self.searchbox.text()) == "" - or n.lower().find(str(self.searchbox.text()).lower()) != -1 - ): + if (self.searchbox.text()) == "" or n.lower().find( + self.searchbox.text().lower() + ) != -1: # Strip channel membership prefixes n = n.strip("~").strip("@").strip("+").strip("&").strip("%") item = QtWidgets.QListWidgetItem(n) @@ -1875,18 +1873,16 @@ class PesterUserlist(QtWidgets.QDialog): @QtCore.pyqtSlot(str, str, str) def updateUserPresent(self, handle, channel, update): - h = str(handle) - c = str(channel) if update == "quit": - self.delUser(h) - elif update == "left" and c == "#pesterchum": - self.delUser(h) - elif update == "join" and c == "#pesterchum": + self.delUser(handle) + elif update == "left" and channel == "#pesterchum": + self.delUser(handle) + elif update == "join" and channel == "#pesterchum": if ( - str(self.searchbox.text()) == "" - or h.lower().find(str(self.searchbox.text()).lower()) != -1 + self.searchbox.text() == "" + or handle.lower().find(self.searchbox.text().lower()) != -1 ): - self.addUser(h) + self.addUser(handle) def addUser(self, name): item = QtWidgets.QListWidgetItem(name) @@ -1936,7 +1932,7 @@ class MemoListItem(QtWidgets.QTreeWidgetItem): def __lt__(self, other): column = self.treeWidget().sortColumn() - if str(self.text(column)).isdigit() and str(other.text(column)).isdigit(): + if (self.text(column)).isdigit() and (other.text(column)).isdigit(): return int(self.text(column)) < int(other.text(column)) return self.text(column) < other.text(column) diff --git a/parsetools.py b/parsetools.py index 3718938..c0fa2c5 100644 --- a/parsetools.py +++ b/parsetools.py @@ -66,7 +66,7 @@ def lexer(string, objlist): for oType, regexp in objlist: newstringlist = [] for stri, s in enumerate(stringlist): - if type(s) not in [str, str]: + if not isinstance(s, str): newstringlist.append(s) continue lasti = 0 @@ -268,9 +268,8 @@ class mecmd(lexercon.Chunk): kxpclexer = lexercon.Pesterchum() -def kxlexMsg(string): - # Do a bit of sanitization. - msg = str(string) +def kxlexMsg(msg: str): + """Do a bit of sanitization.""" # TODO: Let people paste line-by-line normally. Maybe have a mass-paste # right-click option? msg = msg.replace("\n", " ").replace("\r", " ") @@ -327,7 +326,7 @@ def balance(lexed): balanced.append(colorEnd("")) if len(balanced) == 0: balanced.append("") - if type(balanced[len(balanced) - 1]) not in [str, str]: + if not isinstance(balanced[len(balanced) - 1], str): balanced.append("") return balanced @@ -336,12 +335,12 @@ def convertTags(lexed, format="html"): if format not in ["html", "bbcode", "ctag", "text"]: raise ValueError("Color format not recognized") - if type(lexed) in [str, str]: + if isinstance(lexed, str): lexed = lexMessage(lexed) escaped = "" # firststr = True for i, o in enumerate(lexed): - if type(o) in [str, str]: + if isinstance(o, str): if format == "html": escaped += ( o.replace("&", "&").replace(">", ">").replace("<", "<") @@ -370,7 +369,7 @@ def _max_msg_len(mask=None, target=None, nick=None, ident=None): if mask is not None: # Since this will be included in what we send - limit -= len(str(mask)) + limit -= len(mask) else: # Since we should always be able to fetch this # karxi: ... Which we can't, right now, unlike in the old script. @@ -996,9 +995,7 @@ def parseRegexpFunctions(to): return parsed -def img2smiley(string): - string = str(string) - +def img2smiley(string: str): def imagerep(mo): return reverse_smiley[mo.group(1)] diff --git a/pytwmn.py b/pytwmn.py index b88023c..8543a1e 100755 --- a/pytwmn.py +++ b/pytwmn.py @@ -54,8 +54,8 @@ def init(host="127.0.0.1", port=None): class Notification: def __init__(self, title="", msg="", icon=""): - self.title = str(title) - self.msg = str(msg) + self.title = title + self.msg = msg if icon.startswith("file://"): icon = icon[7:] self.icon = icon @@ -68,16 +68,16 @@ class Notification: try: if self.time is None: s.send( - "" + self.title + "" - "" + self.msg + "" - "" + self.icon + "" + f"{self.title}" + f"{self.msg}" + f"{self.icon}" ) else: s.send( - "" + self.title + "" - "" + self.msg + "" - "" + self.icon + "" - "" + str(self.time) + "" + f"{self.title}" + f"{self.msg}" + f"{self.icon}" + f"{self.time}" ) except: raise TwmnError(TwmnError.NO_TWMND) diff --git a/randomer.py b/randomer.py index 7dc809f..4460d71 100644 --- a/randomer.py +++ b/randomer.py @@ -77,6 +77,6 @@ class RandomHandler(QtCore.QObject): msgbox.setInformativeText("Try again later :(") msgbox.exec() return - name = str(l[1]) + name = l[1] PchumLog.info("Random Encounter name is: %s", name) self.mainwindow.newConversation(name) diff --git a/toast.py b/toast.py index 04e914c..66afb06 100644 --- a/toast.py +++ b/toast.py @@ -303,7 +303,7 @@ class PesterToast(QtWidgets.QWidget, DefaultToast): self.msg.setText( PesterToast.wrapText( self.msg.font(), - str(self.msg.text()), + self.msg.text(), self.parent().theme["toasts/width"], self.parent().theme["toasts/content/style"], ) @@ -328,7 +328,7 @@ class PesterToast(QtWidgets.QWidget, DefaultToast): def done(self): QtWidgets.QWidget.hide(self) t = self.machine.toasts[0] - if t.title == str(self.title.text()) and t.msg == str(self.content): + if t.title == self.title.text() and t.msg == self.content: self.machine.toasts.pop(0) self.machine.displaying = False if self.machine.on: diff --git a/user_profile.py b/user_profile.py index d6b4db6..25abf07 100644 --- a/user_profile.py +++ b/user_profile.py @@ -621,7 +621,7 @@ class userProfile: self.chat = user self.userprofile = { "handle": user.handle, - "color": str(user.color.name()), + "color": user.color.name(), "quirks": [], "theme": "pesterchum", }