Mon, 12 Apr 2021 19:54:29 +0200
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 1).
--- a/eric6/Cooperation/Connection.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/Cooperation/Connection.py Mon Apr 12 19:54:29 2021 +0200 @@ -425,10 +425,8 @@ @param participants list of participants (list of strings of "host:port") """ - if participants: - message = SeparatorToken.join(participants) - else: - message = "<empty>" + message = (SeparatorToken.join(participants) if participants + else "<empty>") msg = QByteArray(message.encode("utf-8")) data = QByteArray("{0}{1}{2}{1}".format( Connection.ProtocolParticipants, SeparatorToken, msg.size())
--- a/eric6/DataViews/PyCoverageDialog.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/DataViews/PyCoverageDialog.py Mon Apr 12 19:54:29 2021 +0200 @@ -204,10 +204,7 @@ '') n = len(statements) m = n - len(missing) - if n > 0: - pc = 100.0 * m / n - else: - pc = 100.0 + pc = 100.0 * m / n if n > 0 else 100.0 self.__createResultItem( file, str(n), str(m), pc, readableEx, readable)
--- a/eric6/DebugClients/Python/AsyncFile.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/DebugClients/Python/AsyncFile.py Mon Apr 12 19:54:29 2021 +0200 @@ -227,11 +227,7 @@ line = self.sock.recv(size, socket.MSG_PEEK) eol = line.find(b'\n') - - if eol >= 0: - size = eol + 1 - else: - size = len(line) + size = eol + 1 if eol >= 0 else len(line) # Now we know how big the line is, read it for real. return self.sock.recv(size).decode('utf8', 'backslashreplace')
--- a/eric6/DebugClients/Python/DebugClientBase.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/DebugClients/Python/DebugClientBase.py Mon Apr 12 19:54:29 2021 +0200 @@ -1959,10 +1959,7 @@ cf = cf.f_back frmnr -= 1 - if cf is None: - globaldict = self.debugMod.__dict__ - else: - globaldict = cf.f_globals + globaldict = self.debugMod.__dict__ if cf is None else cf.f_globals globalCompleter = Completer(globaldict).complete self.__getCompletionList(text, globalCompleter, completions) @@ -2026,10 +2023,7 @@ port = os.getenv('ERICPORT', 42424) remoteAddress = self.__resolveHost(host) - if filename is not None: - name = os.path.basename(filename) - else: - name = "" + name = os.path.basename(filename) if filename is not None else "" self.connectDebugger(port, remoteAddress, redirect, name=name) if filename is not None: self.running = os.path.abspath(filename) @@ -2187,10 +2181,7 @@ host, version = host.split("@@") except ValueError: version = 'v4' - if version == 'v4': - family = socket.AF_INET - else: - family = socket.AF_INET6 + family = socket.AF_INET if version == 'v4' else socket.AF_INET6 retryCount = 0 while retryCount < 10:
--- a/eric6/DebugClients/Python/FlexCompleter.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/DebugClients/Python/FlexCompleter.py Mon Apr 12 19:54:29 2021 +0200 @@ -209,10 +209,7 @@ matches.append(match) if matches or not noprefix: break - if noprefix == '_': - noprefix = '__' - else: - noprefix = None + noprefix = '__' if noprefix == '_' else None matches.sort() return matches
--- a/eric6/Debugger/CallTraceViewer.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/Debugger/CallTraceViewer.py Mon Apr 12 19:54:29 2021 +0200 @@ -185,10 +185,7 @@ itm = self.callTrace.topLevelItem(0) while itm is not None: isCall = itm.data(0, Qt.ItemDataRole.UserRole) - if isCall: - call = "->" - else: - call = "<-" + call = "->" if isCall else "<-" f.write("{0} {1} || {2}\n".format( call, itm.text(1), itm.text(2)))
--- a/eric6/Debugger/DebugUI.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/Debugger/DebugUI.py Mon Apr 12 19:54:29 2021 +0200 @@ -837,10 +837,7 @@ """ self.editorOpen = True - if fn: - editor = self.viewmanager.getOpenEditor(fn) - else: - editor = None + editor = self.viewmanager.getOpenEditor(fn) if fn else None self.__checkActions(editor) def __lastEditorClosed(self): @@ -867,10 +864,7 @@ @param editor editor window """ - if editor: - fn = editor.getFileName() - else: - fn = None + fn = editor.getFileName() if editor else None cap = 0 if fn: @@ -1635,10 +1629,7 @@ for row in range(model.rowCount()): index = model.index(row, 0) filename, line, cond = model.getBreakPointByIndex(index)[:3] - if not cond: - formattedCond = "" - else: - formattedCond = " : {0}".format(cond[:20]) + formattedCond = " : {0}".format(cond[:20]) if cond else "" bpSuffix = " : {0:d}{1}".format(line, formattedCond) act = self.breakpointsMenu.addAction( "{0}{1}".format( @@ -1987,10 +1978,8 @@ # Get the command line arguments, the working directory and the # exception reporting flag. - if runProject: - cap = self.tr("Run Project") - else: - cap = self.tr("Run Script") + cap = (self.tr("Run Project") if runProject + else self.tr("Run Script")) dlg = StartDialog( cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory, self.envHistory, self.exceptions, self.ui, 1, @@ -2127,10 +2116,8 @@ # Get the command line arguments, the working directory and the # exception reporting flag. - if debugProject: - cap = self.tr("Debug Project") - else: - cap = self.tr("Debug Script") + cap = (self.tr("Debug Project") if debugProject + else self.tr("Debug Script")) dlg = StartDialog( cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory, self.envHistory, self.exceptions, self.ui, 0,
--- a/eric6/Debugger/DebuggerInterfacePython.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/Debugger/DebuggerInterfacePython.py Mon Apr 12 19:54:29 2021 +0200 @@ -914,10 +914,8 @@ @param temp flag indicating a temporary breakpoint @type bool """ - if debuggerId: - debuggerList = [debuggerId] - else: - debuggerList = list(self.__connections.keys()) + debuggerList = ([debuggerId] if debuggerId + else list(self.__connections.keys())) for debuggerId in debuggerList: self.__sendJsonCommand("RequestBreakpoint", { "filename": self.translate(fn, False), @@ -940,10 +938,8 @@ @param enable flag indicating enabling or disabling a breakpoint @type bool """ - if debuggerId: - debuggerList = [debuggerId] - else: - debuggerList = list(self.__connections.keys()) + debuggerList = ([debuggerId] if debuggerId + else list(self.__connections.keys())) for debuggerId in debuggerList: self.__sendJsonCommand("RequestBreakpointEnable", { "filename": self.translate(fn, False), @@ -964,10 +960,8 @@ @param count number of occurrences to ignore @type int """ - if debuggerId: - debuggerList = [debuggerId] - else: - debuggerList = list(self.__connections.keys()) + debuggerList = ([debuggerId] if debuggerId + else list(self.__connections.keys())) for debuggerId in debuggerList: self.__sendJsonCommand("RequestBreakpointIgnore", { "filename": self.translate(fn, False), @@ -988,10 +982,8 @@ @param temp flag indicating a temporary watch expression @type bool """ - if debuggerId: - debuggerList = [debuggerId] - else: - debuggerList = list(self.__connections.keys()) + debuggerList = ([debuggerId] if debuggerId + else list(self.__connections.keys())) for debuggerId in debuggerList: # cond is combination of cond and special (s. watch expression # viewer) @@ -1012,10 +1004,8 @@ @param enable flag indicating enabling or disabling a watch expression @type bool """ - if debuggerId: - debuggerList = [debuggerId] - else: - debuggerList = list(self.__connections.keys()) + debuggerList = ([debuggerId] if debuggerId + else list(self.__connections.keys())) for debuggerId in debuggerList: # cond is combination of cond and special (s. watch expression # viewer) @@ -1036,10 +1026,8 @@ @param count number of occurrences to ignore @type int """ - if debuggerId: - debuggerList = [debuggerId] - else: - debuggerList = list(self.__connections.keys()) + debuggerList = ([debuggerId] if debuggerId + else list(self.__connections.keys())) for debuggerId in debuggerList: # cond is combination of cond and special (s. watch expression # viewer)
--- a/eric6/Debugger/EditBreakpointDialog.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/Debugger/EditBreakpointDialog.py Mon Apr 12 19:54:29 2021 +0200 @@ -143,10 +143,7 @@ ignore count) """ fn = self.filenamePicker.currentText() - if not fn: - fn = None - else: - fn = os.path.expanduser(os.path.expandvars(fn)) + fn = os.path.expanduser(os.path.expandvars(fn)) if fn else None return (fn, self.linenoSpinBox.value(), self.conditionCombo.currentText(),
--- a/eric6/Debugger/VariablesViewer.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/Debugger/VariablesViewer.py Mon Apr 12 19:54:29 2021 +0200 @@ -271,11 +271,7 @@ self.openItems = [] self.closedItems = [] - if globalScope: - visibility = self.tr("Globals") - else: - visibility = self.tr("Locals") - + visibility = self.tr("Globals") if globalScope else self.tr("Locals") self.rootNode = VariableItem(None, visibility, self.tr("Type"), self.tr("Value")) @@ -482,10 +478,8 @@ @param pathlist full path to the variable @type list of str """ - if parentIdx.isValid(): - parent = parentIdx.internalPointer() - else: - parent = self.rootNode + parent = (parentIdx.internalPointer() if parentIdx.isValid() + else self.rootNode) parent.newItems.clear() parent.changedItems.clear() @@ -540,10 +534,7 @@ @return number of rows @rtype int """ - if parent.isValid(): - node = parent.internalPointer() - else: - node = self.rootNode + node = parent.internalPointer() if parent.isValid() else self.rootNode return len(node.children) @@ -591,10 +582,7 @@ if not self.hasIndex(row, column, parent): return QModelIndex() - if not parent.isValid(): - node = self.rootNode - else: - node = parent.internalPointer() + node = parent.internalPointer() if parent.isValid() else self.rootNode return self.createIndex(row, column, node.children[row])
--- a/eric6/DocumentationTools/ModuleDocumentor.py Mon Apr 12 19:25:18 2021 +0200 +++ b/eric6/DocumentationTools/ModuleDocumentor.py Mon Apr 12 19:54:29 2021 +0200 @@ -331,10 +331,8 @@ self.__checkDeprecated(sectionDict[name].description) and self.listEntryDeprecatedTemplate or "", })) - if kwSuffix: - n = "{0} ({1})".format(name, kwSuffix) - else: - n = "{0}".format(name) + n = ("{0} ({1})".format(name, kwSuffix) if kwSuffix + else "{0}".format(name)) self.keywords.append((n, "#{0}".format(name))) return ''.join(lst) @@ -347,10 +345,7 @@ @return The globals list section. (string) """ attrNames = [] - if class_ is not None: - scope = class_ - else: - scope = self.module + scope = class_ if class_ is not None else self.module attrNames = sorted(attr for attr in scope.globals.keys() if not scope.globals[attr].isSignal) if attrNames: @@ -418,10 +413,7 @@ for className in classNames: _class = self.module.classes[className] supers = _class.super - if len(supers) > 0: - supers = ', '.join(supers) - else: - supers = 'None' + supers = ', '.join(supers) if len(supers) > 0 else "None" globalsList = self.__genGlobalsListSection(_class) classMethList, classMethBodies = self.__genMethodSection( @@ -633,10 +625,7 @@ for className in classNames: _class = obj.classes[className] supers = _class.super - if len(supers) > 0: - supers = ', '.join(supers) - else: - supers = 'None' + supers = ', '.join(supers) if len(supers) > 0 else "None" methList, methBodies = self.__genMethodSection( _class, className, Function.General) @@ -1167,10 +1156,7 @@ elif not inTagSection: lastItem.append(ditem) - if paragraphs: - description = self.__genParagraphs(paragraphs) - else: - description = "" + description = self.__genParagraphs(paragraphs) if paragraphs else "" if paramList: parameterSect = self.parametersListTemplate.format(