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

Tue, 13 Apr 2021 19:59:17 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 13 Apr 2021 19:59:17 +0200
changeset 8235
78e6d29eb773
parent 8234
fcb6b4b96274
child 8236
695777f04b25

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

eric6/Project/CreateDialogCodeDialog.py file | annotate | diff | comparison | revisions
eric6/Project/IdlCompilerOptionsDialog.py file | annotate | diff | comparison | revisions
eric6/Project/Project.py file | annotate | diff | comparison | revisions
eric6/Project/ProjectBrowserModel.py file | annotate | diff | comparison | revisions
eric6/Project/ProjectFormsBrowser.py file | annotate | diff | comparison | revisions
eric6/Project/ProjectResourcesBrowser.py file | annotate | diff | comparison | revisions
eric6/Project/ProjectTranslationsBrowser.py file | annotate | diff | comparison | revisions
eric6/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric6/QScintilla/Lexers/Lexer.py file | annotate | diff | comparison | revisions
eric6/QScintilla/Lexers/SubstyledLexer.py file | annotate | diff | comparison | revisions
eric6/QScintilla/MarkupProviders/HtmlProvider.py file | annotate | diff | comparison | revisions
eric6/QScintilla/MarkupProviders/MarkdownProvider.py file | annotate | diff | comparison | revisions
eric6/QScintilla/MarkupProviders/RestructuredTextProvider.py file | annotate | diff | comparison | revisions
eric6/QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
eric6/QScintilla/Shell.py file | annotate | diff | comparison | revisions
eric6/SqlBrowser/SqlBrowserWidget.py file | annotate | diff | comparison | revisions
eric6/Templates/TemplateViewer.py file | annotate | diff | comparison | revisions
eric6/Tools/TrayStarter.py file | annotate | diff | comparison | revisions
eric6/UI/BrowserModel.py file | annotate | diff | comparison | revisions
eric6/UI/DiffDialog.py file | annotate | diff | comparison | revisions
eric6/UI/FindFileDialog.py file | annotate | diff | comparison | revisions
eric6/UI/Previewers/PreviewerHTML.py file | annotate | diff | comparison | revisions
eric6/UI/PythonDisViewer.py file | annotate | diff | comparison | revisions
eric6/UI/UserInterface.py file | annotate | diff | comparison | revisions
eric6/Utilities/FtpUtilities.py file | annotate | diff | comparison | revisions
eric6/Utilities/crypto/__init__.py file | annotate | diff | comparison | revisions
eric6/Utilities/crypto/py3AES.py file | annotate | diff | comparison | revisions
eric6/ViewManager/ViewManager.py file | annotate | diff | comparison | revisions
eric6/VirtualEnv/VirtualenvExecDialog.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Bookmarks/AddBookmarkDialog.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Bookmarks/NsHtmlWriter.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/CookieJar/CookieExceptionsModel.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Download/DownloadManager.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Feeds/FeedsDialog.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Network/EricSchemeHandler.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/QtHelp/QtHelpDocumentationDialog.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/SpeedDial/PageThumbnailer.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/StatusBar/JavaScriptIcon.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserSingleApplication.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserTabWidget.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/ZoomManager/ZoomManager.py file | annotate | diff | comparison | revisions
scripts/install-i18n.py file | annotate | diff | comparison | revisions
--- a/eric6/Project/CreateDialogCodeDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/CreateDialogCodeDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -98,10 +98,7 @@
             
             try:
                 splitExt = os.path.splitext(self.srcFile)
-                if len(splitExt) == 2:
-                    exts = [splitExt[1]]
-                else:
-                    exts = None
+                exts = [splitExt[1]] if len(splitExt) == 2 else None
                 from Utilities import ModuleParser
                 self.__module = ModuleParser.readModule(
                     self.srcFile, extensions=exts, caching=False)
@@ -561,10 +558,8 @@
             sourceImpl[appendAtIndex:appendAtIndex] = slotsCode
         
         # write the new code
-        if self.project.useSystemEol():
-            newline = None
-        else:
-            newline = self.project.getEolString()
+        newline = (None if self.project.useSystemEol()
+                   else self.project.getEolString())
         fn = self.filenameEdit.text()
         try:
             with open(fn, 'w', encoding="utf-8", newline=newline) as srcFile:
--- a/eric6/Project/IdlCompilerOptionsDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/IdlCompilerOptionsDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -132,10 +132,8 @@
         """
         Private slot to add an 'Include Directory'.
         """
-        if self.__project:
-            defaultDirectory = self.__project.getProjectPath()
-        else:
-            defaultDirectory = ""
+        defaultDirectory = (self.__project.getProjectPath() if self.__project
+                            else "")
         path, ok = E5PathPickerDialog.getPath(
             self,
             self.tr("Include Directory"),
--- a/eric6/Project/Project.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/Project.py	Tue Apr 13 19:59:17 2021 +0200
@@ -1565,12 +1565,9 @@
         """
         dirty = False
         
-        if os.path.isabs(fn):
-            # make it relative to the project root, if it starts with that path
-            newfn = self.getRelativePath(fn)
-        else:
-            # assume relative paths are relative to the project root
-            newfn = fn
+        # make it relative to the project root, if it starts with that path
+        # assume relative paths are relative to the project root
+        newfn = self.getRelativePath(fn) if os.path.isabs(fn) else fn
         newdir = os.path.dirname(newfn)
         
         if isSourceFile:
@@ -2218,10 +2215,7 @@
             if entry.startswith(dn):
                 self.pdata["OTHERS"].remove(entry)
                 dirty = True
-        if not dn.endswith(os.sep):
-            dn2 = dn + os.sep
-        else:
-            dn2 = dn
+        dn2 = dn if dn.endswith(os.sep) else dn + os.sep
         for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
                     "TRANSLATIONS", ]:
             for entry in self.pdata[key][:]:
@@ -4561,10 +4555,7 @@
         self.recentMenu.clear()
         
         for idx, rp in enumerate(self.recent, start=1):
-            if idx < 10:
-                formatStr = '&{0:d}. {1}'
-            else:
-                formatStr = '{0:d}. {1}'
+            formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
             act = self.recentMenu.addAction(
                 formatStr.format(
                     idx,
@@ -4686,10 +4677,7 @@
                 # set fn to project relative name
                 # then reset ns to fully qualified name for insertion,
                 # possibly.
-                if directory == "":
-                    fn = ns
-                else:
-                    fn = os.path.join(directory, ns)
+                fn = os.path.join(directory, ns) if directory else ns
                 ns = os.path.abspath(os.path.join(curpath, ns))
                 
                 # do not bother with dirs here...
@@ -5327,10 +5315,7 @@
         
         # write the file
         try:
-            if self.pdata["EOL"] == 0:
-                newline = None
-            else:
-                newline = self.getEolString()
+            newline = None if self.pdata["EOL"] == 0 else self.getEolString()
             with open(pkglist, "w", encoding="utf-8",
                       newline=newline) as pkglistFile:
                 pkglistFile.write("\n".join(header) + "\n")
--- a/eric6/Project/ProjectBrowserModel.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/ProjectBrowserModel.py	Tue Apr 13 19:59:17 2021 +0200
@@ -438,15 +438,10 @@
         for key in keys:
             # Show the entry in bold in the others browser to make it more
             # distinguishable
-            if key == "OTHERS":
-                bold = True
-            else:
-                bold = False
-            
-            if key == "SOURCES":
-                sourceLanguage = self.project.getProjectLanguage()
-            else:
-                sourceLanguage = ""
+            bold = key == "OTHERS"
+            sourceLanguage = (
+                self.project.getProjectLanguage() if key == "SOURCES" else ""
+            )
             
             for fn in self.project.pdata[key]:
                 fname = os.path.join(self.project.ppath, fn)
@@ -551,10 +546,7 @@
         """
         # Show the entry in bold in the others browser to make it more
         # distinguishable
-        if typeString == "OTHERS":
-            bold = True
-        else:
-            bold = False
+        bold = typeString == "OTHERS"
         
         fname = os.path.join(self.project.ppath, name)
         parentItem, dt = self.findParentItemByName(
@@ -627,10 +619,7 @@
         @return index of the item found (QModelIndex)
         """
         itm = self.findItem(name)
-        if itm is None:
-            index = QModelIndex()
-        else:
-            index = self.createIndex(itm.row(), 0, itm)
+        index = self.createIndex(itm.row(), 0, itm) if itm else QModelIndex()
         return index
     
     def itemIndexByNameAndLine(self, name, lineno):
--- a/eric6/Project/ProjectFormsBrowser.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/ProjectFormsBrowser.py	Tue Apr 13 19:59:17 2021 +0200
@@ -757,10 +757,8 @@
         ):
             ofn = os.path.join(self.project.ppath, self.compiledFile)
             try:
-                if self.project.useSystemEol():
-                    newline = None
-                else:
-                    newline = self.project.getEolString()
+                newline = (None if self.project.useSystemEol()
+                           else self.project.getEolString())
                 with open(ofn, "w", encoding="utf-8", newline=newline) as f:
                     for line in self.buf.splitlines():
                         f.write(line + "\n")
--- a/eric6/Project/ProjectResourcesBrowser.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/ProjectResourcesBrowser.py	Tue Apr 13 19:59:17 2021 +0200
@@ -495,10 +495,8 @@
                     return
             
             try:
-                if self.project.useSystemEol():
-                    newline = None
-                else:
-                    newline = self.project.getEolString()
+                newline = (None if self.project.useSystemEol()
+                           else self.project.getEolString())
                 with open(fname, 'w', encoding="utf-8",
                           newline=newline) as rcfile:
                     rcfile.write('<!DOCTYPE RCC>\n')
@@ -602,10 +600,8 @@
         ):
             ofn = os.path.join(self.project.ppath, self.compiledFile)
             try:
-                if self.project.useSystemEol():
-                    newline = None
-                else:
-                    newline = self.project.getEolString()
+                newline = (None if self.project.useSystemEol()
+                           else self.project.getEolString())
                 with open(ofn, "w", encoding="utf-8", newline=newline) as f:
                     for line in self.buf.splitlines():
                         f.write(line + "\n")
--- a/eric6/Project/ProjectTranslationsBrowser.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Project/ProjectTranslationsBrowser.py	Tue Apr 13 19:59:17 2021 +0200
@@ -985,10 +985,7 @@
         @param generateAll flag indicating whether all translations should be
             generated (boolean)
         """
-        if generateAll:
-            langs = []
-        else:
-            langs = self.getSelectedItems()
+        langs = [] if generateAll else self.getSelectedItems()
         
         # Hook support
         if generateAll:
@@ -1230,10 +1227,7 @@
         @param generateAll flag indicating whether all translations should be
             released (boolean)
         """
-        if generateAll:
-            langs = []
-        else:
-            langs = self.getSelectedItems()
+        langs = [] if generateAll else self.getSelectedItems()
         
         # Hooks support
         if generateAll:
--- a/eric6/QScintilla/Editor.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/Editor.py	Tue Apr 13 19:59:17 2021 +0200
@@ -3936,10 +3936,7 @@
         
         # get the selection boundaries
         lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
-        if indexTo == 0:
-            endLine = lineTo - 1
-        else:
-            endLine = lineTo
+        endLine = lineTo if indexTo else lineTo - 1
         
         self.beginUndoAction()
         # iterate over the lines
@@ -3967,10 +3964,7 @@
         
         # get the selection boundaries
         lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
-        if indexTo == 0:
-            endLine = lineTo - 1
-        else:
-            endLine = lineTo
+        endLine = lineTo if indexTo else lineTo - 1
         
         self.beginUndoAction()
         # iterate over the lines
@@ -4113,10 +4107,7 @@
         
         # get the selection boundaries
         lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
-        if indexTo == 0:
-            endLine = lineTo - 1
-        else:
-            endLine = lineTo
+        endLine = lineTo if indexTo else lineTo - 1
         
         self.beginUndoAction()
         # iterate over the lines
@@ -4180,11 +4171,7 @@
         
         # get the selection
         lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
-        
-        if indexTo == 0:
-            endLine = lineTo - 1
-        else:
-            endLine = lineTo
+        endLine = lineTo if indexTo else lineTo - 1
         
         self.beginUndoAction()
         # iterate over the lines
@@ -7043,10 +7030,7 @@
             @type str
             """
             startChar = encString[0]
-            if len(encString) == 2:
-                endChar = encString[1]
-            else:
-                endChar = startChar
+            endChar = encString[1] if len(encString) == 2 else startChar
             
             sline, sindex, eline, eindex = self.getSelection()
             replaceText = startChar + self.selectedText() + endChar
@@ -8341,10 +8325,7 @@
         wordEndPos = self.positionFromLineIndex(line, wordEnd)
         
         regExp = re.compile(r"\b{0}\b".format(word))
-        if forward:
-            startPos = wordEndPos
-        else:
-            startPos = wordStartPos
+        startPos = wordEndPos if forward else wordStartPos
         
         matches = [m for m in regExp.finditer(self.text())]
         if matches:
--- a/eric6/QScintilla/Lexers/Lexer.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/Lexers/Lexer.py	Tue Apr 13 19:59:17 2021 +0200
@@ -158,10 +158,7 @@
         if lineFrom != self.lastIndented:
             self.lastIndentedIndex = indexFrom
         
-        if indexTo == 0:
-            endLine = lineTo - 1
-        else:
-            endLine = lineTo
+        endLine = lineTo if indexTo else lineTo - 1
         
         # get the indentation difference
         indentDifference = self.getIndentationDifference(lineFrom, editor)
--- a/eric6/QScintilla/Lexers/SubstyledLexer.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/Lexers/SubstyledLexer.py	Tue Apr 13 19:59:17 2021 +0200
@@ -298,31 +298,16 @@
                     col = self.paper(baseStyle)
                     color = col.red() << 16 | col.green() << 8 | col.blue()
                 settings.setValue(substyleKey + "paper", color)
-                if "eolfill" in style:
-                    eolfill = style["eolfill"]
-                else:
-                    eolfill = self.eolFill(baseStyle)
+                eolfill = style.get("eolfill", self.eolFill(baseStyle))
                 settings.setValue(substyleKey + "eolfill", eolfill)
                 font = self.font(baseStyle)
-                if "font_family" in style:
-                    family = style["font_family"]
-                else:
-                    family = font.family()
+                family = style.get("font_family", font.family())
                 settings.setValue(substyleKey + "font_family", family)
-                if "font_size" in style:
-                    size = style["font_size"]
-                else:
-                    size = font.pointSize()
+                size = style.get("font_size", font.pointSize())
                 settings.setValue(substyleKey + "font_size", size)
-                if "font_bold" in style:
-                    bold = style["font_bold"]
-                else:
-                    bold = font.bold()
+                bold = style.get("font_bold", font.bold())
                 settings.setValue(substyleKey + "font_bold", bold)
-                if "font_italic" in style:
-                    italic = style["font_italic"]
-                else:
-                    italic = font.italic()
+                italic = style.get("font_italic", font.italic())
                 settings.setValue(substyleKey + "font_italic", italic)
                 if "font_underline" in style:
                     underline = style["font_underline"]
@@ -357,10 +342,8 @@
         @return number of defined sub-styles
         @rtype int
         """
-        if style in self.__subStyles:
-            count = len(self.__subStyles[style])
-        else:
-            count = 0
+        count = (len(self.__subStyles[style]) if style in self.__subStyles
+                 else 0)
         
         return count
     
--- a/eric6/QScintilla/MarkupProviders/HtmlProvider.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/MarkupProviders/HtmlProvider.py	Tue Apr 13 19:59:17 2021 +0200
@@ -175,10 +175,7 @@
         if editor is None:
             return
         
-        if addEol:
-            lineSeparator = editor.getLineSeparator()
-        else:
-            lineSeparator = ""
+        lineSeparator = editor.getLineSeparator() if addEol else ""
         editor.beginUndoAction()
         if editor.hasSelectedText():
             newText = "<{0}>{2}{1}</{0}>{2}".format(
--- a/eric6/QScintilla/MarkupProviders/MarkdownProvider.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/MarkupProviders/MarkdownProvider.py	Tue Apr 13 19:59:17 2021 +0200
@@ -364,10 +364,7 @@
         if editor is None:
             return
         
-        if numberedList:
-            markup = "  1. "
-        else:
-            markup = "  * "
+        markup = "  1. " if numberedList else "  * "
         lineSeparator = editor.getLineSeparator()
         editor.beginUndoAction()
         if editor.hasSelectedText():
--- a/eric6/QScintilla/MarkupProviders/RestructuredTextProvider.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/MarkupProviders/RestructuredTextProvider.py	Tue Apr 13 19:59:17 2021 +0200
@@ -392,10 +392,7 @@
         if editor is None:
             return
         
-        if numberedList:
-            markup = "  #. "
-        else:
-            markup = "  * "
+        markup = "  #. " if numberedList else "  * "
         lineSeparator = editor.getLineSeparator()
         editor.beginUndoAction()
         if editor.hasSelectedText():
--- a/eric6/QScintilla/MiniEditor.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/MiniEditor.py	Tue Apr 13 19:59:17 2021 +0200
@@ -113,10 +113,7 @@
             @type str
             """
             startChar = encString[0]
-            if len(encString) == 2:
-                endChar = encString[1]
-            else:
-                endChar = startChar
+            endChar = encString[1] if len(encString) == 2 else startChar
             
             sline, sindex, eline, eindex = self.getSelection()
             replaceText = startChar + self.selectedText() + endChar
--- a/eric6/QScintilla/Shell.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/QScintilla/Shell.py	Tue Apr 13 19:59:17 2021 +0200
@@ -1962,10 +1962,7 @@
             that something was found
         @rtype tuple of (int, bool)
         """
-        if startIdx == -1:
-            idx = 0
-        else:
-            idx = startIdx + 1
+        idx = 0 if startIdx == -1 else startIdx + 1
         while (
             idx < len(self.__history) and
             not self.__history[idx].startswith(txt)
@@ -1987,10 +1984,7 @@
             that something was found
         @rtype tuple of (int, bool)
         """
-        if startIdx == -1:
-            idx = len(self.__history) - 1
-        else:
-            idx = startIdx - 1
+        idx = len(self.__history) - 1 if startIdx == -1 else startIdx - 1
         while (
             idx >= 0 and
             not self.__history[idx].startswith(txt)
--- a/eric6/SqlBrowser/SqlBrowserWidget.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/SqlBrowser/SqlBrowserWidget.py	Tue Apr 13 19:59:17 2021 +0200
@@ -262,10 +262,7 @@
             return
         
         insertIndex = self.table.currentIndex()
-        if insertIndex.row() == -1:
-            row = 0
-        else:
-            row = insertIndex.row()
+        row = 0 if insertIndex.row() == -1 else insertIndex.row()
         model.insertRow(row)
         insertIndex = model.index(row, 0)
         self.table.setCurrentIndex(insertIndex)
--- a/eric6/Templates/TemplateViewer.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Templates/TemplateViewer.py	Tue Apr 13 19:59:17 2021 +0200
@@ -513,10 +513,7 @@
         Private slot to handle the Edit context menu action.
         """
         itm = self.currentItem()
-        if isinstance(itm, TemplateEntry):
-            editGroup = False
-        else:
-            editGroup = True
+        editGroup = not isinstance(itm, TemplateEntry)
         
         from .TemplatePropertiesDialog import TemplatePropertiesDialog
         dlg = TemplatePropertiesDialog(self, editGroup, itm)
--- a/eric6/Tools/TrayStarter.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Tools/TrayStarter.py	Tue Apr 13 19:59:17 2021 +0200
@@ -428,10 +428,7 @@
         self.recentProjectsMenu.clear()
         
         for idx, rp in enumerate(self.recentProjects, start=1):
-            if idx < 10:
-                formatStr = '&{0:d}. {1}'
-            else:
-                formatStr = '{0:d}. {1}'
+            formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
             act = self.recentProjectsMenu.addAction(
                 formatStr.format(
                     idx, Utilities.compactPath(rp, self.maxMenuFilePathLen)))
@@ -448,10 +445,7 @@
         self.recentMultiProjectsMenu.clear()
         
         for idx, rmp in enumerate(self.recentMultiProjects, start=1):
-            if idx < 10:
-                formatStr = '&{0:d}. {1}'
-            else:
-                formatStr = '{0:d}. {1}'
+            formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
             act = self.recentMultiProjectsMenu.addAction(
                 formatStr.format(
                     idx, Utilities.compactPath(rmp, self.maxMenuFilePathLen)))
@@ -468,10 +462,7 @@
         self.recentFilesMenu.clear()
         
         for idx, rf in enumerate(self.recentFiles, start=1):
-            if idx < 10:
-                formatStr = '&{0:d}. {1}'
-            else:
-                formatStr = '{0:d}. {1}'
+            formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
             act = self.recentFilesMenu.addAction(
                 formatStr.format(
                     idx, Utilities.compactPath(rf, self.maxMenuFilePathLen)))
--- a/eric6/UI/BrowserModel.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/UI/BrowserModel.py	Tue Apr 13 19:59:17 2021 +0200
@@ -76,10 +76,8 @@
         if parent is None:
             parent = QModelIndex()
         
-        if parent.isValid():
-            item = parent.internalPointer()
-        else:
-            item = self.rootItem
+        item = (parent.internalPointer() if parent.isValid()
+                else self.rootItem)
         
         return item.columnCount() + 1
     
@@ -1044,12 +1042,7 @@
         @param full flag indicating full pathname should be displayed (boolean)
         """
         self._dirName = os.path.abspath(dinfo)
-        
-        if full:
-            dn = self._dirName
-        else:
-            dn = os.path.basename(self._dirName)
-        
+        dn = self._dirName if full else os.path.basename(self._dirName)
         BrowserItem.__init__(self, parent, dn)
         
         self.type_ = BrowserItemDirectory
@@ -1073,11 +1066,7 @@
         @param full flag indicating full pathname should be displayed (boolean)
         """
         self._dirName = os.path.abspath(dinfo)
-        
-        if full:
-            dn = self._dirName
-        else:
-            dn = os.path.basename(self._dirName)
+        dn = self._dirName if full else os.path.basename(self._dirName)
         self.itemData[0] = dn
     
     def dirName(self):
--- a/eric6/UI/DiffDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/UI/DiffDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -101,10 +101,7 @@
         filesystem.
         """
         dname, fname = Utilities.splitPath(self.filename2)
-        if fname != '.':
-            fname = "{0}.diff".format(self.filename2)
-        else:
-            fname = dname
+        fname = "{0}.diff".format(self.filename2) if fname != '.' else dname
             
         fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
             self,
--- a/eric6/UI/FindFileDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/UI/FindFileDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -438,10 +438,7 @@
         wo = self.wordCheckBox.isChecked()
         cs = self.caseCheckBox.isChecked()
         ct = self.findtextCombo.currentText()
-        if reg:
-            txt = ct
-        else:
-            txt = re.escape(ct)
+        txt = ct if reg else re.escape(ct)
         if wo:
             txt = "\\b{0}\\b".format(txt)
         flags = re.UNICODE
@@ -610,10 +607,7 @@
             start = 0
             end = 0
         
-        if self.project:
-            fn = os.path.join(self.project.ppath, file)
-        else:
-            fn = file
+        fn = os.path.join(self.project.ppath, file) if self.project else file
         if fn.endswith('.ui'):
             self.designerFile.emit(fn)
         else:
@@ -777,10 +771,7 @@
         Private method to copy the path of an entry to the clipboard.
         """
         itm = self.findList.selectedItems()[0]
-        if itm.parent():
-            fn = itm.parent().text(0)
-        else:
-            fn = itm.text(0)
+        fn = itm.parent().text(0) if itm.parent() else itm.text(0)
         
         cb = QApplication.clipboard()
         cb.setText(fn)
--- a/eric6/UI/Previewers/PreviewerHTML.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/UI/Previewers/PreviewerHTML.py	Tue Apr 13 19:59:17 2021 +0200
@@ -276,10 +276,7 @@
                 "return res;"
                 "})()"
             )
-            if pos is not None:
-                pos = QPoint(pos["x"], pos["y"])
-            else:
-                pos = QPoint(0, 0)
+            pos = QPoint(0, 0) if pos is None else QPoint(pos["x"], pos["y"])
         self.__scrollBarPositions[self.__previewedPath] = pos
         self.__hScrollBarAtEnd[self.__previewedPath] = False
         self.__vScrollBarAtEnd[self.__previewedPath] = False
--- a/eric6/UI/PythonDisViewer.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/UI/PythonDisViewer.py	Tue Apr 13 19:59:17 2021 +0200
@@ -474,10 +474,7 @@
             return
         
         filename = self.__editor.getFileName()
-        if filename:
-            filename = os.path.basename(filename)
-        else:
-            filename = "<dis>"
+        filename = os.path.basename(filename) if filename else "<dis>"
         
         with E5OverrideCursor():
             try:
--- a/eric6/UI/UserInterface.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/UI/UserInterface.py	Tue Apr 13 19:59:17 2021 +0200
@@ -1403,10 +1403,7 @@
         # flag indicating '--' options was found
         ddseen = False
         
-        if Utilities.isWindowsPlatform():
-            argChars = ['-', '/']
-        else:
-            argChars = ['-']
+        argChars = ['-', '/'] if Utilities.isWindowsPlatform() else ['-']
 
         for arg in args:
             # handle a request to start with last session
@@ -3746,10 +3743,7 @@
         except (ImportError, AttributeError):
             sip_version_str = "sip version not available"
         
-        if sys.maxsize > 2**32:
-            sizeStr = "64-Bit"
-        else:
-            sizeStr = "32-Bit"
+        sizeStr = "64-Bit" if sys.maxsize > 2**32 else "32-Bit"
         
         versionText = self.tr(
             """<h2>Version Numbers</h2>"""
@@ -3851,10 +3845,7 @@
         @param deleteAttachFile flag indicating to delete the file after
             it has been read (boolean)
         """
-        if mode == "feature":
-            address = FeatureAddress
-        else:
-            address = BugAddress
+        address = FeatureAddress if mode == "feature" else BugAddress
         subject = "[eric] "
         if attachFile is not None:
             with open(attachFile, "r", encoding="utf-8") as f:
@@ -6483,11 +6474,8 @@
         
         @param editor editor window
         """
-        if editor:
-            fn = editor.getFileName()
-        else:
-            fn = None
-            
+        fn = editor.getFileName() if editor else None
+        
         if fn:
             dbs = e5App().getObject("DebugServer")
             for language in dbs.getSupportedLanguages():
--- a/eric6/Utilities/FtpUtilities.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Utilities/FtpUtilities.py	Tue Apr 13 19:59:17 2021 +0200
@@ -236,10 +236,7 @@
         """
         try:
             month, day, year = [int(part) for part in date.split('-')]
-            if year >= 70:
-                year = 1900 + year
-            else:
-                year = 2000 + year
+            year = 1900 + year if year >= 70 else 2000 + year
         except (ValueError, IndexError):
             raise FtpDirLineParserError(
                 "illegal date string '{0}'".format(month))
--- a/eric6/Utilities/crypto/__init__.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Utilities/crypto/__init__.py	Tue Apr 13 19:59:17 2021 +0200
@@ -253,11 +253,7 @@
     @param newPassword new password to be used (string)
     """
     global MasterPassword
-    
-    if newPassword == "":
-        MasterPassword = None
-    else:
-        MasterPassword = pwEncode(newPassword)
+    MasterPassword = pwEncode(newPassword) if newPassword else None
 
 
 def dataEncrypt(data, password, keyLength=32, hashIterations=10000):
--- a/eric6/Utilities/crypto/py3AES.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/Utilities/crypto/py3AES.py	Tue Apr 13 19:59:17 2021 +0200
@@ -312,10 +312,7 @@
         @return modified state (bytearray)
         """
         state = state[:]
-        if isInv:
-            getter = self.__getSBoxInvert
-        else:
-            getter = self.__getSBoxValue
+        getter = self.__getSBoxInvert if isInv else self.__getSBoxValue
         for i in range(16):
             state[i] = getter(state[i])
         return state
@@ -389,10 +386,7 @@
         @return modified column (bytearray)
         """
         column = column[:]
-        if isInv:
-            mult = [14, 9, 13, 11]
-        else:
-            mult = [2, 1, 1, 3]
+        mult = [14, 9, 13, 11] if isInv else [2, 1, 1, 3]
         cpy = column[:]
         g = self.__galois_multiplication
 
@@ -634,10 +628,8 @@
         """
         if end - start > 16:
             end = start + 16
-        if mode == self.ModeOfOperation["CBC"]:
-            ar = bytearray(16)
-        else:
-            ar = bytearray()
+        ar = (bytearray(16) if mode == self.ModeOfOperation["CBC"]
+              else bytearray())
 
         i = start
         j = 0
--- a/eric6/ViewManager/ViewManager.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/ViewManager/ViewManager.py	Tue Apr 13 19:59:17 2021 +0200
@@ -5163,10 +5163,7 @@
         self.recentMenu.clear()
         
         for idx, rs in enumerate(self.recent, start=1):
-            if idx < 10:
-                formatStr = '&{0:d}. {1}'
-            else:
-                formatStr = '{0:d}. {1}'
+            formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}'
             act = self.recentMenu.addAction(
                 formatStr.format(
                     idx,
@@ -6303,10 +6300,7 @@
         Preferences.Prefs.settings.setValue(
             'Bookmarked/Sources', self.bookmarked)
         
-        if len(self.editors):
-            res = False
-        else:
-            res = True
+        res = len(self.editors) == 0
         
         if not res:
             e5App().focusChanged.connect(self.appFocusChanged)
--- a/eric6/VirtualEnv/VirtualenvExecDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/VirtualEnv/VirtualenvExecDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -287,10 +287,7 @@
         """
         Private method to write a script file to the virtualenv directory.
         """
-        if self.__pyvenv:
-            basename = "create_pyvenv"
-        else:
-            basename = "create_virtualenv"
+        basename = "create_pyvenv" if self.__pyvenv else "create_virtualenv"
         if isWindowsPlatform():
             script = os.path.join(self.__targetDir, basename + ".cmd")
             txt = self.__cmd
--- a/eric6/WebBrowser/Bookmarks/AddBookmarkDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/Bookmarks/AddBookmarkDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -237,10 +237,8 @@
             idx = self.__bookmarksManager.bookmarksModel().index(0, 0)
         parent = self.__bookmarksManager.bookmarksModel().node(idx)
         
-        if self.__addFolder:
-            type_ = BookmarkNode.Folder
-        else:
-            type_ = BookmarkNode.Bookmark
+        type_ = (BookmarkNode.Folder if self.__addFolder
+                 else BookmarkNode.Bookmark)
         bookmark = BookmarkNode(type_)
         bookmark.title = self.nameEdit.text()
         if not self.__addFolder:
--- a/eric6/WebBrowser/Bookmarks/NsHtmlWriter.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/Bookmarks/NsHtmlWriter.py	Tue Apr 13 19:59:17 2021 +0200
@@ -134,10 +134,7 @@
         @param node reference to the node to be written (BookmarkNode)
         @param indent size of the indentation (integer)
         """
-        if node.expanded:
-            folded = ""
-        else:
-            folded = " FOLDED"
+        folded = "" if node.expanded else " FOLDED"
         
         if node.added.isValid():
             added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t())
--- a/eric6/WebBrowser/CookieJar/CookieExceptionsModel.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/CookieJar/CookieExceptionsModel.py	Tue Apr 13 19:59:17 2021 +0200
@@ -234,10 +234,7 @@
         
         # Avoid to have similar rules (with or without leading dot)
         # e.g. python-projects.org and .python-projects.org
-        if host.startswith("."):
-            otherRule = host[1:]
-        else:
-            otherRule = '.' + host
+        otherRule = host[1:] if host.startswith(".") else '.' + host
         if otherRule in addList:
             addList.remove(otherRule)
         if otherRule in removeList1:
--- a/eric6/WebBrowser/Download/DownloadManager.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/Download/DownloadManager.py	Tue Apr 13 19:59:17 2021 +0200
@@ -270,10 +270,7 @@
                     return
         
         window = WebBrowserWindow.getWindow()
-        if window:
-            pageUrl = window.currentBrowser().url()
-        else:
-            pageUrl = QUrl()
+        pageUrl = window.currentBrowser().url() if window else QUrl()
         from .DownloadItem import DownloadItem
         itm = DownloadItem(downloadItem=downloadItem, pageUrl=pageUrl,
                            parent=self)
@@ -307,10 +304,7 @@
         itm.downloadFinished.connect(self.__finished)
         
         # insert at top of window
-        if append:
-            row = self.downloadsCount()
-        else:
-            row = 0
+        row = self.downloadsCount() if append else 0
         self.__model.beginInsertRows(QModelIndex(), row, row)
         if append:
             self.__downloads.append(itm)
--- a/eric6/WebBrowser/Feeds/FeedsDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/Feeds/FeedsDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -71,10 +71,8 @@
         if not url.isValid():
             return
         
-        if button.feed[0]:
-            title = button.feed[0]
-        else:
-            title = self.__browser.url().host()
+        title = (button.feed[0] if button.feed[0]
+                 else self.__browser.url().host())
         
         from WebBrowser.WebBrowserWindow import WebBrowserWindow
         feedsManager = WebBrowserWindow.feedsManager()
--- a/eric6/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/GreaseMonkey/GreaseMonkeyScript.py	Tue Apr 13 19:59:17 2021 +0200
@@ -305,10 +305,7 @@
             index = line.find(" ")
             
             key = line[:index].strip()
-            if index > 0:
-                value = line[index + 1:].strip()
-            else:
-                value = ""
+            value = line[index + 1:].strip() if index > 0 else ""
             
             if not key:
                 continue
--- a/eric6/WebBrowser/Network/EricSchemeHandler.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/Network/EricSchemeHandler.py	Tue Apr 13 19:59:17 2021 +0200
@@ -216,10 +216,7 @@
         page = page.replace("@ERIC_LINK@", self.tr("About eric"))
         page = page.replace("@HEADER_TITLE@", self.tr("eric Web Browser"))
         page = page.replace("@SUBMIT@", self.tr("Search!"))
-        if e5App().isLeftToRight():
-            ltr = "LTR"
-        else:
-            ltr = "RTL"
+        ltr = "LTR" if e5App().isLeftToRight() else"RTL"
         page = page.replace("@QT_LAYOUT_DIRECTION@", ltr)
         
         return page
--- a/eric6/WebBrowser/QtHelp/QtHelpDocumentationDialog.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/QtHelp/QtHelpDocumentationDialog.py	Tue Apr 13 19:59:17 2021 +0200
@@ -269,10 +269,7 @@
         
         # save the current and selected filters
         currentFilter = self.filtersList.currentItem()
-        if currentFilter:
-            currentFilterText = currentFilter.text()
-        else:
-            currentFilterText = ""
+        currentFilterText = currentFilter.text() if currentFilter else ""
         selectedFiltersText = [
             itm.text() for itm in self.filtersList.selectedItems()]
         
--- a/eric6/WebBrowser/SpeedDial/PageThumbnailer.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/SpeedDial/PageThumbnailer.py	Tue Apr 13 19:59:17 2021 +0200
@@ -88,10 +88,7 @@
         
         @return title of the thumbnail (string)
         """
-        if self.__title:
-            title = self.__title
-        else:
-            title = self.__url.host()
+        title = self.__title if self.__title else self.__url.host()
         if not title:
             title = self.__url.toString()
         return title
--- a/eric6/WebBrowser/StatusBar/JavaScriptIcon.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/StatusBar/JavaScriptIcon.py	Tue Apr 13 19:59:17 2021 +0200
@@ -151,10 +151,8 @@
         @param page reference to the web page
         @type WebBrowserPage
         """
-        if url.scheme() in ("eric", "qthelp"):
-            enable = True
-        else:
-            enable = self.__settings[page]
+        enable = (True if url.scheme() in ("eric", "qthelp")
+                  else self.__settings[page])
         if isMainFrame:
             page.settings().setAttribute(
                 QWebEngineSettings.WebAttribute.JavascriptEnabled, enable)
--- a/eric6/WebBrowser/WebBrowserSingleApplication.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/WebBrowserSingleApplication.py	Tue Apr 13 19:59:17 2021 +0200
@@ -141,10 +141,7 @@
         if args is None:
             return
         
-        if Globals.isWindowsPlatform():
-            argChars = ('-', '/')
-        else:
-            argChars = ('-', )
+        argChars = ('-', '/') if Globals.isWindowsPlatform() else ('-', )
         
         for arg in args:
             if arg.startswith("--search="):
--- a/eric6/WebBrowser/WebBrowserTabWidget.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/WebBrowserTabWidget.py	Tue Apr 13 19:59:17 2021 +0200
@@ -504,10 +504,7 @@
         @return reference to the new browser
         @rtype WebBrowserView
         """
-        if browser:
-            position = self.indexOf(browser) + 1
-        else:
-            position = -1
+        position = self.indexOf(browser) + 1 if browser else -1
         return self.newBrowser(link, position, background)
     
     def __showNavigationMenu(self):
--- a/eric6/WebBrowser/WebBrowserView.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/WebBrowserView.py	Tue Apr 13 19:59:17 2021 +0200
@@ -2240,15 +2240,8 @@
         @return tuple containing the title, URL and web icon
         @rtype tuple of (str, str, QIcon)
         """
-        if "Title" in sessionData:
-            title = sessionData["Title"]
-        else:
-            title = ""
-        
-        if "Url" in sessionData:
-            urlStr = sessionData["Url"]
-        else:
-            urlStr = ""
+        title = sessionData.get("Title", "")
+        urlStr = sessionData.get("Url", "")
         
         if "Icon" in sessionData:
             iconArray = QByteArray.fromBase64(
--- a/eric6/WebBrowser/WebBrowserWindow.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/WebBrowserWindow.py	Tue Apr 13 19:59:17 2021 +0200
@@ -4085,10 +4085,7 @@
         @param name name for the action
         @type str
         """
-        if name:
-            act = QAction(name, parentMenu)
-        else:
-            act = QAction(codec, parentMenu)
+        act = QAction(name, parentMenu) if name else QAction(codec, parentMenu)
         act.setData(codec)
         act.setCheckable(True)
         if defaultCodec == codec:
--- a/eric6/WebBrowser/ZoomManager/ZoomManager.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/eric6/WebBrowser/ZoomManager/ZoomManager.py	Tue Apr 13 19:59:17 2021 +0200
@@ -142,11 +142,8 @@
         if not key:
             zoom = 100
         
-        if key in self.__zoomDB:
-            zoom = self.__zoomDB[key]
-        else:
-            # default zoom value (i.e. no zoom)
-            zoom = 100
+        # default zoom value (i.e. no zoom)
+        zoom = self.__zoomDB.get(key, 100)
         
         return zoom
     
--- a/scripts/install-i18n.py	Tue Apr 13 18:02:59 2021 +0200
+++ b/scripts/install-i18n.py	Tue Apr 13 19:59:17 2021 +0200
@@ -69,10 +69,8 @@
     """
     global privateInstall, configDir
     
-    if privateInstall:
-        targetDir = configDir
-    else:
-        targetDir = getConfig('ericTranslationsDir')
+    targetDir = (configDir if privateInstall
+                 else getConfig('ericTranslationsDir'))
     
     try:
         for fn in glob.glob(os.path.join('eric', 'eric6', 'i18n', '*.qm')):

eric ide

mercurial