Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).

Tue, 20 Apr 2021 19:47:39 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 20 Apr 2021 19:47:39 +0200
changeset 8257
28146736bbfc
parent 8256
26a8b92aeabd
child 8258
82b608e352ec

Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).

eric6/CondaInterface/Conda.py file | annotate | diff | comparison | revisions
eric6/CondaInterface/CondaExportDialog.py file | annotate | diff | comparison | revisions
eric6/CondaInterface/CondaNewEnvironmentDataDialog.py file | annotate | diff | comparison | revisions
eric6/CondaInterface/CondaPackagesWidget.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugBase.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric6/Debugger/BreakPointViewer.py file | annotate | diff | comparison | revisions
eric6/Debugger/CallStackViewer.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebugUI.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebuggerInterfacePython.py file | annotate | diff | comparison | revisions
eric6/Debugger/ExceptionLogger.py file | annotate | diff | comparison | revisions
eric6/Debugger/StartDialog.py file | annotate | diff | comparison | revisions
eric6/Debugger/WatchPointViewer.py file | annotate | diff | comparison | revisions
eric6/DocumentationTools/ModuleDocumentor.py file | annotate | diff | comparison | revisions
eric6/E5Graphics/E5ArrowItem.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5ErrorMessage.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5LineEdit.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5PathPicker.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5TabWidget.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5TextEditSearchWidget.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5ZoomWidget.py file | annotate | diff | comparison | revisions
eric6/E5Network/E5SslCertificateSelectionDialog.py file | annotate | diff | comparison | revisions
eric6/E5XML/HighlightingStylesReader.py file | annotate | diff | comparison | revisions
eric6/E5XML/TasksWriter.py file | annotate | diff | comparison | revisions
eric6/Globals/__init__.py file | annotate | diff | comparison | revisions
eric6/Graphics/AssociationItem.py file | annotate | diff | comparison | revisions
eric6/Graphics/ImportsDiagramBuilder.py file | annotate | diff | comparison | revisions
eric6/Graphics/PackageDiagramBuilder.py file | annotate | diff | comparison | revisions
eric6/Graphics/UMLClassDiagramBuilder.py file | annotate | diff | comparison | revisions
eric6/Graphics/UMLDialog.py file | annotate | diff | comparison | revisions
eric6/MicroPython/MicroPythonCommandsInterface.py file | annotate | diff | comparison | revisions
--- a/eric6/CondaInterface/Conda.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/CondaInterface/Conda.py	Tue Apr 20 19:47:39 2021 +0200
@@ -92,10 +92,11 @@
                     rootPrefix()
                 ]
             for pathPrefix in pathPrefixes:
-                if Globals.isWindowsPlatform():
-                    python = os.path.join(pathPrefix, "python.exe")
-                else:
-                    python = os.path.join(pathPrefix, "bin", "python")
+                python = (
+                    os.path.join(pathPrefix, "python.exe")
+                    if Globals.isWindowsPlatform() else
+                    os.path.join(pathPrefix, "bin", "python")
+                )
                 if os.path.exists(python):
                     break
             else:
--- a/eric6/CondaInterface/CondaExportDialog.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/CondaInterface/CondaExportDialog.py	Tue Apr 20 19:47:39 2021 +0200
@@ -107,14 +107,15 @@
         """
         Private slot to refresh the displayed list.
         """
-        if self.__requirementsEdited:
-            ok = E5MessageBox.yesNo(
+        ok = (
+            E5MessageBox.yesNo(
                 self,
                 self.tr("Generate Requirements"),
                 self.tr("""The requirements were changed. Do you want"""
                         """ to overwrite these changes?"""))
-        else:
-            ok = True
+            if self.__requirementsEdited else
+            True
+        )
         if ok:
             self.start()
     
--- a/eric6/CondaInterface/CondaNewEnvironmentDataDialog.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/CondaInterface/CondaNewEnvironmentDataDialog.py	Tue Apr 20 19:47:39 2021 +0200
@@ -99,10 +99,11 @@
             name and the requirements file name
         @rtype tuple of (str, str, str)
         """
-        if self.__requirementsMode:
-            requirementsFile = self.requirementsFilePicker.text()
-        else:
-            requirementsFile = ""
+        requirementsFile = (
+            self.requirementsFilePicker.text()
+            if self.__requirementsMode else
+            ""
+        )
         
         return (
             self.nameEdit.text(),
--- a/eric6/CondaInterface/CondaPackagesWidget.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/CondaInterface/CondaPackagesWidget.py	Tue Apr 20 19:47:39 2021 +0200
@@ -357,11 +357,12 @@
         pattern = self.searchEdit.text()
         if pattern:
             with E5OverrideCursor():
-                if CondaInterface.condaVersion() >= (4, 4, 0):
-                    prefix = ""
-                else:
-                    prefix = self.environmentsComboBox.itemData(
+                prefix = (
+                    ""
+                    if CondaInterface.condaVersion() >= (4, 4, 0) else
+                    self.environmentsComboBox.itemData(
                         self.environmentsComboBox.currentIndex())
+                )
                 ok, result = self.__conda.searchPackages(
                     pattern,
                     fullNameOnly=self.fullNameButton.isChecked(),
--- a/eric6/DebugClients/Python/DebugBase.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/DebugClients/Python/DebugBase.py	Tue Apr 20 19:47:39 2021 +0200
@@ -922,11 +922,11 @@
         if excval is None:
             excval = ''
         
-        if unhandled:
-            exctypetxt = "unhandled {0!s}".format(str(exctype))
-        else:
-            exctypetxt = str(exctype)
-        
+        exctypetxt = (
+            "unhandled {0!s}".format(str(exctype))
+            if unhandled else
+            str(exctype)
+        )
         excvaltxt = str(excval)
         
         # Don't step into libraries, which are used by our debugger methods
--- a/eric6/DebugClients/Python/DebugClientBase.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Tue Apr 20 19:47:39 2021 +0200
@@ -1522,10 +1522,8 @@
         else:
             varDict = f.f_locals
         
-        if scope == -1:
-            varlist = []
-        else:
-            varlist = self.__formatVariablesList(varDict, scope, filterList)
+        varlist = [] if scope == -1 else self.__formatVariablesList(
+            varDict, scope, filterList)
         
         self.sendJsonCommand("ResponseVariables", {
             "scope": scope,
@@ -1806,10 +1804,11 @@
         filterList = [] if filterList is None else filterList[:]
         
         varlist = []
-        if scope:
-            patternFilterObjects = self.globalsFilterObjects
-        else:
-            patternFilterObjects = self.localsFilterObjects
+        patternFilterObjects = (
+            self.globalsFilterObjects
+            if scope else
+            self.localsFilterObjects
+        )
         if type(dict_) == dict:
             dict_ = dict_.items()
         
@@ -2144,10 +2143,11 @@
             })
         else:
             code = self.__compileFileSource(self.running)
-        if code:
-            res = self.mainThread.run(code, self.debugMod.__dict__, debug=True)
-        else:
-            res = 42        # should not happen
+        res = (
+            self.mainThread.run(code, self.debugMod.__dict__, debug=True)
+            if code else
+            42        # should not happen
+        )
         return res
 
     def run_call(self, scriptname, func, *args):
--- a/eric6/Debugger/BreakPointViewer.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/BreakPointViewer.py	Tue Apr 20 19:47:39 2021 +0200
@@ -144,16 +144,17 @@
         if not index.isValid():
             return
         
-        if selected:
-            flags = QItemSelectionModel.SelectionFlags(
+        flags = (
+            QItemSelectionModel.SelectionFlags(
                 QItemSelectionModel.SelectionFlag.ClearAndSelect |
                 QItemSelectionModel.SelectionFlag.Rows
             )
-        else:
-            flags = QItemSelectionModel.SelectionFlags(
+            if selected else
+            QItemSelectionModel.SelectionFlags(
                 QItemSelectionModel.SelectionFlag.Deselect |
                 QItemSelectionModel.SelectionFlag.Rows
             )
+        )
         self.selectionModel().select(index, flags)
         
     def __createPopupMenus(self):
--- a/eric6/Debugger/CallStackViewer.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/CallStackViewer.py	Tue Apr 20 19:47:39 2021 +0200
@@ -136,22 +136,24 @@
         
         self.__callStackList.clear()
         for fname, fline, ffunc, fargs in stack:
-            if self.__projectMode:
-                dfname = self.__project.getRelativePath(fname)
-            else:
-                dfname = fname
-            if ffunc and not ffunc.startswith("<"):
+            dfname = (
+                self.__project.getRelativePath(fname)
+                if self.__projectMode else
+                fname
+            )
+            itm = (
                 # use normal format
-                itm = QTreeWidgetItem(
+                QTreeWidgetItem(
                     self.__callStackList,
                     [self.__entryFormat.format(dfname, fline, ffunc, fargs)]
                 )
-            else:
+                if ffunc and not ffunc.startswith("<") else
                 # use short format
-                itm = QTreeWidgetItem(
+                QTreeWidgetItem(
                     self.__callStackList,
                     [self.__entryFormatShort.format(dfname, fline)]
                 )
+            )
             itm.setData(0, self.FilenameRole, fname)
             itm.setData(0, self.LinenoRole, fline)
         
--- a/eric6/Debugger/DebugUI.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/DebugUI.py	Tue Apr 20 19:47:39 2021 +0200
@@ -1687,10 +1687,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        if runProject:
-            cap = self.tr("Coverage of Project")
-        else:
-            cap = self.tr("Coverage of Script")
+        cap = (
+            self.tr("Coverage of Project")
+            if runProject else
+            self.tr("Coverage of Script")
+        )
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 2,
@@ -1831,10 +1832,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        if runProject:
-            cap = self.tr("Profile of Project")
-        else:
-            cap = self.tr("Profile of Script")
+        cap = (
+            self.tr("Profile of Project")
+            if runProject else
+            self.tr("Profile of Script")
+        )
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 3,
@@ -1975,8 +1977,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        cap = (self.tr("Run Project") if runProject
-               else 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,
@@ -2113,8 +2118,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        cap = (self.tr("Debug Project") if debugProject
-               else 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	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/DebuggerInterfacePython.py	Tue Apr 20 19:47:39 2021 +0200
@@ -209,10 +209,11 @@
                                            "DebugClients", "Python",
                                            "DebugClient.py")
         
-        if configOverride and configOverride["enable"]:
-            redirect = str(configOverride["redirect"])
-        else:
-            redirect = str(Preferences.getDebugger("Python3Redirect"))
+        redirect = (
+            str(configOverride["redirect"])
+            if configOverride and configOverride["enable"] else
+            str(Preferences.getDebugger("Python3Redirect"))
+        )
         noencoding = (Preferences.getDebugger("Python3NoEncoding") and
                       '--no-encoding' or '')
         multiprocessEnabled = (
@@ -369,10 +370,11 @@
         if not venvName and project.getProjectLanguage() == "Python3":
             venvName = Preferences.getDebugger("Python3VirtualEnv")
         
-        if configOverride and configOverride["enable"]:
-            redirect = str(configOverride["redirect"])
-        else:
-            redirect = str(project.getDebugProperty("REDIRECT"))
+        redirect = (
+            str(configOverride["redirect"])
+            if configOverride and configOverride["enable"] else
+            str(project.getDebugProperty("REDIRECT"))
+        )
         noencoding = (
             '--no-encoding' if project.getDebugProperty("NOENCODING") else ''
         )
--- a/eric6/Debugger/ExceptionLogger.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/ExceptionLogger.py	Tue Apr 20 19:47:39 2021 +0200
@@ -110,12 +110,12 @@
                 .format(debuggerId))
             return
         
-        if not exceptionMessage:
-            text = self.tr("{0}: {1}").format(
-                debuggerId, exceptionType)
-        else:
-            text = self.tr("{0}: {1}, {2}").format(
-                debuggerId, exceptionType, exceptionMessage)
+        text = (
+            self.tr("{0}: {1}").format(debuggerId, exceptionType)
+            if not exceptionMessage else
+            self.tr("{0}: {1}, {2}").format(debuggerId, exceptionType,
+                                            exceptionMessage)
+        )
         
         itm.setText(0, text)
         itm.setToolTip(0, text)
--- a/eric6/Debugger/StartDialog.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/StartDialog.py	Tue Apr 20 19:47:39 2021 +0200
@@ -354,13 +354,14 @@
             lists
         @rtype tuple of four list of str
         """
-        if self.dialogType == 0:
-            noDebugHistory = [
+        noDebugHistory = (
+            [
                 self.ui.multiprocessNoDebugCombo.itemText(index)
                 for index in range(self.ui.multiprocessNoDebugCombo.count())
             ]
-        else:
-            noDebugHistory = None
+            if self.dialogType == 0 else
+            None
+        )
         return (
             [self.ui.cmdlineCombo.itemText(index) for index in range(
                 self.ui.cmdlineCombo.count())],
--- a/eric6/Debugger/WatchPointViewer.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Debugger/WatchPointViewer.py	Tue Apr 20 19:47:39 2021 +0200
@@ -126,14 +126,15 @@
         if not index.isValid():
             return
         
-        if selected:
-            flags = QItemSelectionModel.SelectionFlags(
+        flags = (
+            QItemSelectionModel.SelectionFlags(
                 QItemSelectionModel.SelectionFlag.ClearAndSelect |
                 QItemSelectionModel.SelectionFlag.Rows)
-        else:
-            flags = QItemSelectionModel.SelectionFlags(
+            if selected else
+            QItemSelectionModel.SelectionFlags(
                 QItemSelectionModel.SelectionFlag.Deselect |
                 QItemSelectionModel.SelectionFlag.Rows)
+        )
         self.selectionModel().select(index, flags)
         
     def __createPopupMenus(self):
--- a/eric6/DocumentationTools/ModuleDocumentor.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/DocumentationTools/ModuleDocumentor.py	Tue Apr 20 19:47:39 2021 +0200
@@ -304,10 +304,11 @@
             
         classesSection = self.__genClassesSection()
         functionsSection = self.__genFunctionsSection()
-        if self.module.type == RB_SOURCE:
-            rbModulesSection = self.__genRbModulesSection()
-        else:
-            rbModulesSection = ""
+        rbModulesSection = (
+            self.__genRbModulesSection()
+            if self.module.type == RB_SOURCE else
+            ""
+        )
         return "{0}{1}{2}{3}".format(
             modBody, classesSection, rbModulesSection, functionsSection)
         
@@ -349,12 +350,13 @@
         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:
-            s = ''.join(
+        s = (
+            ''.join(
                 [self.listEntrySimpleTemplate.format(**{'Name': name})
                  for name in attrNames])
-        else:
-            s = self.listEntryNoneTemplate
+            if attrNames else
+            self.listEntryNoneTemplate
+        )
         return self.listTemplate.format(**{'Entries': s})
         
     def __genClassListSection(self):
@@ -1157,82 +1159,94 @@
         
         description = self.__genParagraphs(paragraphs) if paragraphs else ""
         
-        if paramList:
-            parameterSect = self.parametersListTemplate.format(
+        parameterSect = (
+            self.parametersListTemplate.format(
                 **{'Parameters': self.__genParamDescriptionListSection(
                     paramList)})
-        else:
-            parameterSect = ""
+            if paramList else
+            ""
+        )
         
-        if returns:
-            returnSect = self.returnsTemplate.format(
+        returnSect = (
+            self.returnsTemplate.format(
                 html_uencode('\n'.join(returns)))
-        else:
-            returnSect = ""
-        
-        if returnTypes:
-            returnTypesSect = self.returnTypesTemplate.format(
-                html_uencode('\n'.join(returnTypes)))
-        else:
-            returnTypesSect = ""
+            if returns else
+            ""
+        )
         
-        if yields:
-            yieldSect = self.yieldsTemplate.format(
-                html_uencode('\n'.join(yields)))
-        else:
-            yieldSect = ""
+        returnTypesSect = (
+            self.returnTypesTemplate.format(
+                html_uencode('\n'.join(returnTypes)))
+            if returnTypes else
+            ""
+        )
         
-        if yieldTypes:
-            yieldTypesSect = self.yieldTypesTemplate.format(
+        yieldSect = (
+            self.yieldsTemplate.format(
+                html_uencode('\n'.join(yields)))
+            if yields else
+            ""
+        )
+        
+        yieldTypesSect = (
+            self.yieldTypesTemplate.format(
                 html_uencode('\n'.join(yieldTypes)))
-        else:
-            yieldTypesSect = ""
+            if yieldTypes else
+            ""
+        )
         
-        if exceptionDict:
-            exceptionSect = self.exceptionsListTemplate.format(
+        exceptionSect = (
+            self.exceptionsListTemplate.format(
                 **{'Exceptions': self.__genDescriptionListSection(
                     exceptionDict, self.exceptionsListEntryTemplate)})
-        else:
-            exceptionSect = ""
+            if exceptionDict else
+            ""
+        )
         
-        if signalDict:
-            signalSect = self.signalsListTemplate.format(
+        signalSect = (
+            self.signalsListTemplate.format(
                 **{'Signals': self.__genDescriptionListSection(
                     signalDict, self.signalsListEntryTemplate)})
-        else:
-            signalSect = ""
+            if signalDict else
+            ""
+        )
         
-        if eventDict:
-            eventSect = self.eventsListTemplate.format(
+        eventSect = (
+            self.eventsListTemplate.format(
                 **{'Events': self.__genDescriptionListSection(
                     eventDict, self.eventsListEntryTemplate)})
-        else:
-            eventSect = ""
+            if eventDict else
+            ""
+        )
         
-        if deprecated:
-            deprecatedSect = self.deprecatedTemplate.format(
+        deprecatedSect = (
+            self.deprecatedTemplate.format(
                 **{'Lines': html_uencode('\n'.join(deprecated))})
-        else:
-            deprecatedSect = ""
+            if deprecated else
+            ""
+        )
         
-        if authorInfo:
-            authorInfoSect = self.authorInfoTemplate.format(
+        authorInfoSect = (
+            self.authorInfoTemplate.format(
                 **{'Authors': html_uencode('\n'.join(authorInfo))})
-        else:
-            authorInfoSect = ""
+            if authorInfo else
+            ""
+        )
         
-        if sinceInfo:
-            sinceInfoSect = self.sinceInfoTemplate.format(
+        sinceInfoSect = (
+            self.sinceInfoTemplate.format(
                 **{'Info': html_uencode(sinceInfo[0])})
-        else:
-            sinceInfoSect = ""
+            if sinceInfo else
+            ""
+        )
         
-        if seeList:
-            seeSect = self.seeListTemplate.format(
+        seeSect = (
+            self.seeListTemplate.format(
                 **{'Links': self.__genSeeListSection(
                     seeList, self.seeListEntryTemplate)})
-        else:
-            seeSect = ''
+            if seeList else
+            ''
+        )
         
         return "".join([
             deprecatedSect, description, parameterSect, returnSect,
--- a/eric6/E5Graphics/E5ArrowItem.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Graphics/E5ArrowItem.py	Tue Apr 20 19:47:39 2021 +0200
@@ -116,13 +116,10 @@
         @param option style options (QStyleOptionGraphicsItem)
         @param widget optional reference to the widget painted on (QWidget)
         """
-        if (
+        width = 2 if (
             (option.state & QStyle.StateFlag.State_Selected) ==
             QStyle.State(QStyle.StateFlag.State_Selected)
-        ):
-            width = 2
-        else:
-            width = 1
+        ) else 1
         
         # draw the line first
         line = QLineF(self._origin, self._end)
--- a/eric6/E5Gui/E5ErrorMessage.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Gui/E5ErrorMessage.py	Tue Apr 20 19:47:39 2021 +0200
@@ -138,15 +138,16 @@
                 .replace("\n", "<br/>")
                 .replace("\r", "<br/>")
             )
-            if context.file is not None:
-                msg = (
+            msg = (
+                (
                     "<p><b>{0}</b></p><p>{1}</p><p>File: {2}</p>"
                     "<p>Line: {3}</p><p>Function: {4}</p>"
                 ).format(messageType, Utilities.html_uencode(message),
                          context.file, context.line, context.function)
-            else:
-                msg = "<p><b>{0}</b></p><p>{1}</p>".format(
+                if context.file is not None else
+                "<p><b>{0}</b></p><p>{1}</p>".format(
                     messageType, Utilities.html_uencode(message))
+            )
             if QThread.currentThread() == e5App().thread():
                 _msgHandlerDialog.showMessage(msg)
             else:
--- a/eric6/E5Gui/E5LineEdit.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Gui/E5LineEdit.py	Tue Apr 20 19:47:39 2021 +0200
@@ -151,10 +151,11 @@
         """
         Protected slot to update the text margins.
         """
-        if self.__leftMargin == 0:
-            left = self.__leftWidget.sizeHint().width()
-        else:
-            left = self.__leftMargin
+        left = (
+            self.__leftWidget.sizeHint().width()
+            if self.__leftMargin == 0 else
+            self.__leftMargin
+        )
         right = self.__rightWidget.sizeHint().width()
         top = 0
         bottom = 0
@@ -222,10 +223,11 @@
         """
         spacing = self.__rightLayout.spacing()
         w = 0
-        if position == self.LeftSide:
-            w = self.__leftWidget.sizeHint().width()
-        else:
-            w = self.__rightWidget.sizeHint().width()
+        w = (
+            self.__leftWidget.sizeHint().width()
+            if position == self.LeftSide else
+            self.__rightWidget.sizeHint().width()
+        )
         if w == 0:
             return 0
         return w + spacing * 2
--- a/eric6/E5Gui/E5PathPicker.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Gui/E5PathPicker.py	Tue Apr 20 19:47:39 2021 +0200
@@ -511,10 +511,11 @@
         directory = self._editorText()
         if not directory and self.__defaultDirectory:
             directory = self.__defaultDirectory
-        if self.__mode == E5PathPickerModes.OpenFilesMode:
-            directory = os.path.expanduser(directory.split(";")[0])
-        else:
-            directory = os.path.expanduser(directory)
+        directory = (
+            os.path.expanduser(directory.split(";")[0])
+            if self.__mode == E5PathPickerModes.OpenFilesMode else
+            os.path.expanduser(directory)
+        )
         if not os.path.isabs(directory) and self.__defaultDirectory:
             directory = os.path.join(self.__defaultDirectory, directory)
         directory = QDir.fromNativeSeparators(directory)
--- a/eric6/E5Gui/E5TabWidget.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Gui/E5TabWidget.py	Tue Apr 20 19:47:39 2021 +0200
@@ -306,10 +306,11 @@
         side = self.__tabBar.style().styleHint(
             QStyle.StyleHint.SH_TabBar_CloseButtonPosition,
             None, None, None)
-        if side == QTabBar.ButtonPosition.LeftSide:
-            side = QTabBar.ButtonPosition.RightSide
-        else:
-            side = QTabBar.ButtonPosition.LeftSide
+        side = (
+            QTabBar.ButtonPosition.RightSide
+            if side == QTabBar.ButtonPosition.LeftSide else
+            QTabBar.ButtonPosition.LeftSide
+        )
         return side
     
     def animationLabel(self, index, animationFile, interval=100):
--- a/eric6/E5Gui/E5TextEditSearchWidget.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Gui/E5TextEditSearchWidget.py	Tue Apr 20 19:47:39 2021 +0200
@@ -291,11 +291,11 @@
         @return flag indicating the search result
         @rtype bool
         """
-        if backwards:
-            flags = QTextDocument.FindFlags(
-                QTextDocument.FindFlag.FindBackward)
-        else:
-            flags = QTextDocument.FindFlags()
+        flags = (
+            QTextDocument.FindFlags(QTextDocument.FindFlag.FindBackward)
+            if backwards else
+            QTextDocument.FindFlags()
+        )
         if self.caseCheckBox.isChecked():
             flags |= QTextDocument.FindFlag.FindCaseSensitively
         if self.wordCheckBox.isChecked():
--- a/eric6/E5Gui/E5ZoomWidget.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Gui/E5ZoomWidget.py	Tue Apr 20 19:47:39 2021 +0200
@@ -279,13 +279,12 @@
         """
         Private slot to determine the width of the zoom value label.
         """
-        if self.__mapped:
-            labelLen = max(len(str(v)) for v in self.__mapping)
-        else:
-            labelLen = max(
-                len(str(self.slider.maximum())),
-                len(str(self.slider.minimum()))
-            )
+        labelLen = (
+            max(len(str(v)) for v in self.__mapping)
+            if self.__mapped else
+            max(len(str(self.slider.maximum())),
+                len(str(self.slider.minimum())))
+        )
         fmtStr = "{0}%" if self.__percent else "{0}"
         label = fmtStr.format("0" * labelLen)
         try:
--- a/eric6/E5Network/E5SslCertificateSelectionDialog.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5Network/E5SslCertificateSelectionDialog.py	Tue Apr 20 19:47:39 2021 +0200
@@ -136,11 +136,12 @@
             self.certificatesTree.selectedItems()[0].parent() is not None
         )
         
-        if valid:
-            certificate = QSslCertificate.fromData(
+        certificate = (
+            QSslCertificate.fromData(
                 self.certificatesTree.selectedItems()[0].data(
                     0, self.CertRole))
-        else:
-            certificate = None
+            if valid else
+            None
+        )
         
         return certificate
--- a/eric6/E5XML/HighlightingStylesReader.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5XML/HighlightingStylesReader.py	Tue Apr 20 19:47:39 2021 +0200
@@ -68,10 +68,11 @@
             "name": language,
             "styles": [],
         })
-        if language and language in self.lexers:
-            lexer = self.lexers[language]
-        else:
-            lexer = None
+        lexer = (
+            self.lexers[language]
+            if language and language in self.lexers else
+            None
+        )
         
         while not self.atEnd():
             self.readNext()
--- a/eric6/E5XML/TasksWriter.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/E5XML/TasksWriter.py	Tue Apr 20 19:47:39 2021 +0200
@@ -67,10 +67,11 @@
                 e5App().getObject("TaskViewer").getTasksScanFilter())
         
         # do the tasks
-        if self.forProject:
-            tasks = e5App().getObject("TaskViewer").getProjectTasks()
-        else:
-            tasks = e5App().getObject("TaskViewer").getGlobalTasks()
+        tasks = (
+            e5App().getObject("TaskViewer").getProjectTasks()
+            if self.forProject else
+            e5App().getObject("TaskViewer").getGlobalTasks()
+        )
         for task in tasks:
             self.writeStartElement("Task")
             self.writeAttribute("priority", str(task.priority))
--- a/eric6/Globals/__init__.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Globals/__init__.py	Tue Apr 20 19:47:39 2021 +0200
@@ -122,10 +122,11 @@
         os.environ.get("XDG_SESSION_DESKTOP", "").lower() or
         os.environ.get("DESKTOP_SESSION", "").lower()
     )
-    if desktop:
-        isKDE = "kde" in desktop or "plasma" in desktop
-    else:
-        isKDE = bool(os.environ.get("KDE_FULL_SESSION", ""))
+    isKDE = (
+        "kde" in desktop or "plasma" in desktop
+        if desktop else
+        bool(os.environ.get("KDE_FULL_SESSION", ""))
+    )
     
     return isKDE
 
@@ -147,10 +148,11 @@
         os.environ.get("XDG_SESSION_DESKTOP", "").lower() or
         os.environ.get("GDMSESSION", "").lower()
     )
-    if desktop:
-        isGnome = "gnome" in desktop
-    else:
-        isGnome = bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", ""))
+    isGnome = (
+        "gnome" in desktop
+        if desktop else
+        bool(os.environ.get("GNOME_DESKTOP_SESSION_ID", ""))
+    )
     
     return isGnome
 
@@ -545,10 +547,11 @@
                               "webBrowserSupport.py")
     proc = QProcess()
     proc.start(sys.executable, [scriptPath, qVersion()])
-    if proc.waitForFinished(10000):
-        variant = str(proc.readAllStandardOutput(), "utf-8", 'replace').strip()
-    else:
-        variant = "None"
+    variant = (
+        str(proc.readAllStandardOutput(), "utf-8", 'replace').strip()
+        if proc.waitForFinished(10000) else
+        "None"
+    )
     return variant
 #
 # eflag: noqa = M801
--- a/eric6/Graphics/AssociationItem.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Graphics/AssociationItem.py	Tue Apr 20 19:47:39 2021 +0200
@@ -322,10 +322,11 @@
         if region == NoRegion:
             return
         
-        if isWidgetA:
-            rect = self.__mapRectFromItem(self.itemA)
-        else:
-            rect = self.__mapRectFromItem(self.itemB)
+        rect = (
+            self.__mapRectFromItem(self.itemA)
+            if isWidgetA else
+            self.__mapRectFromItem(self.itemB)
+        )
         x = rect.x()
         y = rect.y()
         ww = rect.width()
--- a/eric6/Graphics/ImportsDiagramBuilder.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Graphics/ImportsDiagramBuilder.py	Tue Apr 20 19:47:39 2021 +0200
@@ -61,12 +61,12 @@
             os.sep, '.')[1:]
         
         pname = self.project.getProjectName()
-        if pname:
-            name = self.tr("Imports Diagramm {0}: {1}").format(
+        name = (
+            self.tr("Imports Diagramm {0}: {1}").format(
                 pname, self.project.getRelativePath(self.packagePath))
-        else:
-            name = self.tr("Imports Diagramm: {0}").format(
-                self.packagePath)
+            if pname else
+            self.tr("Imports Diagramm: {0}").format(self.packagePath)
+        )
         self.umlView.setDiagramName(name)
     
     def __buildModulesDict(self):
--- a/eric6/Graphics/PackageDiagramBuilder.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Graphics/PackageDiagramBuilder.py	Tue Apr 20 19:47:39 2021 +0200
@@ -47,11 +47,12 @@
         Public method to initialize the object.
         """
         pname = self.project.getProjectName()
-        if pname:
-            name = self.tr("Package Diagram {0}: {1}").format(
+        name = (
+            self.tr("Package Diagram {0}: {1}").format(
                 pname, self.project.getRelativePath(self.package))
-        else:
-            name = self.tr("Package Diagram: {0}").format(self.package)
+            if pname else
+            self.tr("Package Diagram: {0}").format(self.package)
+        )
         self.umlView.setDiagramName(name)
     
     def __getCurrentShape(self, name):
--- a/eric6/Graphics/UMLClassDiagramBuilder.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Graphics/UMLClassDiagramBuilder.py	Tue Apr 20 19:47:39 2021 +0200
@@ -43,11 +43,12 @@
         Public method to initialize the object.
         """
         pname = self.project.getProjectName()
-        if pname and self.project.isProjectSource(self.file):
-            name = self.tr("Class Diagram {0}: {1}").format(
+        name = (
+            self.tr("Class Diagram {0}: {1}").format(
                 pname, self.project.getRelativePath(self.file))
-        else:
-            name = self.tr("Class Diagram: {0}").format(self.file)
+            if pname and self.project.isProjectSource(self.file) else
+            self.tr("Class Diagram: {0}").format(self.file)
+        )
         self.umlView.setDiagramName(name)
         
     def __getCurrentShape(self, name):
--- a/eric6/Graphics/UMLDialog.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/Graphics/UMLDialog.py	Tue Apr 20 19:47:39 2021 +0200
@@ -379,11 +379,12 @@
         @param filename name of the file containing the invalid data (string)
         @param linenum number of the invalid line (integer)
         """
-        if linenum < 0:
-            msg = self.tr("""<p>The file <b>{0}</b> does not contain"""
-                          """ valid data.</p>""").format(filename)
-        else:
-            msg = self.tr("""<p>The file <b>{0}</b> does not contain"""
-                          """ valid data.</p><p>Invalid line: {1}</p>"""
-                          ).format(filename, linenum + 1)
+        msg = (
+            self.tr("""<p>The file <b>{0}</b> does not contain"""
+                    """ valid data.</p>""").format(filename)
+            if linenum < 0 else
+            self.tr("""<p>The file <b>{0}</b> does not contain"""
+                    """ valid data.</p><p>Invalid line: {1}</p>"""
+                    ).format(filename, linenum + 1)
+        )
         E5MessageBox.critical(self, self.tr("Load Diagram"), msg)
--- a/eric6/MicroPython/MicroPythonCommandsInterface.py	Tue Apr 20 19:38:10 2021 +0200
+++ b/eric6/MicroPython/MicroPythonCommandsInterface.py	Tue Apr 20 19:47:39 2021 +0200
@@ -298,19 +298,20 @@
         @rtype tuple of str
         @exception OSError raised to indicate an issue with the device
         """
-        if self.__repl.isMicrobit():
+        commands = (
             # BBC micro:bit does not support directories
-            commands = [
+            [
                 "import os as __os_",
                 "print(__os_.listdir())",
                 "del __os_",
             ]
-        else:
-            commands = [
+            if self.__repl.isMicrobit() else
+            [
                 "import os as __os_",
                 "print(__os_.listdir('{0}'))".format(dirname),
                 "del __os_",
             ]
+        )
         out, err = self.execute(commands)
         if err:
             raise OSError(self.__shortError(err))
@@ -334,9 +335,9 @@
         @rtype tuple of (str, tuple)
         @exception OSError raised to indicate an issue with the device
         """
-        if self.__repl.isMicrobit():
+        commands = (
             # BBC micro:bit does not support directories
-            commands = [
+            [
                 "import os as __os_",
                 "\n".join([
                     "def is_visible(filename, showHidden):",
@@ -357,8 +358,8 @@
                 "print(listdir_stat({0}))".format(showHidden),
                 "del __os_, stat, listdir_stat, is_visible",
             ]
-        else:
-            commands = [
+            if self.__repl.isMicrobit() else
+            [
                 "import os as __os_",
                 "\n".join([
                     "def is_visible(filename, showHidden):",
@@ -388,6 +389,7 @@
                 "print(listdir_stat('{0}', {1}))".format(dirname, showHidden),
                 "del __os_, stat, listdir_stat, is_visible",
             ]
+        )
         out, err = self.execute(commands)
         if err:
             raise OSError(self.__shortError(err))

eric ide

mercurial