Applied some more code simplifications suggested by the new Simplify checker (Y110, Y111: use any() or all()).

Sun, 11 Apr 2021 16:53:48 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 11 Apr 2021 16:53:48 +0200
changeset 8221
0572a215bd2f
parent 8220
006ee31b4835
child 8222
5994b80b8760

Applied some more code simplifications suggested by the new Simplify checker (Y110, Y111: use any() or all()).

eric6.epj file | annotate | diff | comparison | revisions
eric6/Cooperation/CooperationClient.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugUtilities.py file | annotate | diff | comparison | revisions
eric6/E5Gui/E5ErrorMessage.py file | annotate | diff | comparison | revisions
eric6/MicroPython/MicroPythonFileManagerWidget.py file | annotate | diff | comparison | revisions
eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py file | annotate | diff | comparison | revisions
eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/djangoXssVulnerability.py file | annotate | diff | comparison | revisions
eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsPySvn/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsSubversion/ProjectBrowserHelper.py file | annotate | diff | comparison | revisions
eric6/Project/Project.py file | annotate | diff | comparison | revisions
eric6/QScintilla/DocstringGenerator/PyDocstringGenerator.py file | annotate | diff | comparison | revisions
eric6/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric6/Templates/TemplateViewer.py file | annotate | diff | comparison | revisions
eric6/UI/Browser.py file | annotate | diff | comparison | revisions
eric6/UI/LogView.py file | annotate | diff | comparison | revisions
eric6/Utilities/__init__.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/AdBlock/AdBlockMatcher.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Feeds/FeedsManager.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/GreaseMonkey/GreaseMonkeyManager.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Tools/WebBrowserTools.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserPage.py file | annotate | diff | comparison | revisions
--- a/eric6.epj	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6.epj	Sun Apr 11 16:53:48 2021 +0200
@@ -49,7 +49,7 @@
         "DocstringType": "eric",
         "EnabledCheckerCategories": "C, D, E, M, N, Y, W",
         "ExcludeFiles": "*/ThirdParty/*, */coverage/*, */Ui_*.py, */Examples/*, */*_rc.py,*/pycodestyle.py,*/pyflakes/checker.py,*/mccabe.py,*/eradicate.py,*/ast_unparse.py",
-        "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M301,M302,M303,M304,M305,M306,M307,M308,M311,M312,M313,M314,M315,M321,M701,M702,M811,M834,N802,N803,N807,N808,N821,W293,W504,Y110,Y111,Y116,Y119,Y401,Y402",
+        "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M301,M302,M303,M304,M305,M306,M307,M308,M311,M312,M313,M314,M315,M321,M701,M702,M811,M834,N802,N803,N807,N808,N821,W293,W504,Y116,Y119,Y401,Y402",
         "FixCodes": "",
         "FixIssues": false,
         "FutureChecker": "",
--- a/eric6/Cooperation/CooperationClient.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Cooperation/CooperationClient.py	Sun Apr 11 16:53:48 2021 +0200
@@ -136,11 +136,8 @@
         if senderIp not in self.__peers:
             return False
         
-        for connection in self.__peers[senderIp]:
-            if connection.peerPort() == senderPort:
-                return True
-        
-        return False
+        return any(connection.peerPort() == senderPort
+                   for connection in self.__peers[senderIp])
     
     def hasConnections(self):
         """
@@ -148,11 +145,8 @@
         
         @return flag indicating the presence of connections (boolean)
         """
-        for connectionList in self.__peers.values():
-            if connectionList:
-                return True
-        
-        return False
+        return any(bool(connectionList)
+                   for connectionList in self.__peers.values())
     
     def removeConnection(self, connection):
         """
--- a/eric6/DebugClients/Python/DebugClientBase.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Sun Apr 11 16:53:48 2021 +0200
@@ -2397,8 +2397,5 @@
         @return flag indicating eligibility
         @rtype bool
         """
-        for pattern in self.noDebugList:
-            if fnmatch.fnmatch(scriptName, pattern):
-                return True
-        
-        return False
+        return any(fnmatch.fnmatch(scriptName, pattern)
+                   for pattern in self.noDebugList)
--- a/eric6/DebugClients/Python/DebugUtilities.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/DebugClients/Python/DebugUtilities.py	Sun Apr 11 16:53:48 2021 +0200
@@ -193,7 +193,7 @@
                 for line in f:
                     line = line.strip()
                     if line:
-                        for name in PYTHON_NAMES:
+                        for name in PYTHON_NAMES:   # __IGNORE_WARNING_Y110__
                             if line.startswith(
                                 '#!/usr/bin/env {0}'.format(name)
                             ):
@@ -224,9 +224,8 @@
         return False
     
     prog = os.path.basename(program).lower()
-    for pyname in PYTHON_NAMES:
-        if pyname in prog:
-            return True
+    if any(pyname in prog for pyname in PYTHON_NAMES):
+        return True
     
     return (
         not isWindowsPlatform() and
--- a/eric6/E5Gui/E5ErrorMessage.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/E5Gui/E5ErrorMessage.py	Sun Apr 11 16:53:48 2021 +0200
@@ -52,12 +52,11 @@
     @return flag indicating that the message should be filtered out
     @rtype bool
     """
-    for filterStr in Globals.toList(_filterSettings.value(
-            "MessageFilters", [])) + _defaultFilters:
-        if filterStr in message:
-            return True
-    
-    return False
+    return any(
+        filterStr in message
+        for filterStr in Globals.toList(_filterSettings.value(
+            "MessageFilters", [])) + _defaultFilters
+    )
 
 
 class E5ErrorMessage(QErrorMessage):
--- a/eric6/MicroPython/MicroPythonFileManagerWidget.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/MicroPython/MicroPythonFileManagerWidget.py	Sun Apr 11 16:53:48 2021 +0200
@@ -419,12 +419,11 @@
         @rtype bool
         """
         itemCount = treeWidget.topLevelItemCount()
-        if itemCount:
-            for row in range(itemCount):
-                if treeWidget.topLevelItem(row).text(0) == filename:
-                    return True
-        
-        return False
+        return (
+            itemCount > 0 and
+            any(treeWidget.topLevelItem(row).text(0) == filename
+                for row in range(itemCount))
+        )
     
     @pyqtSlot()
     def on_putButton_clicked(self, putAs=False):
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py	Sun Apr 11 16:53:48 2021 +0200
@@ -252,16 +252,16 @@
             """
             return b.startswith(a) or a.startswith(b)
         
-        if self.__noFixCodes:
-            for noFixCode in [c.strip() for c in self.__noFixCodes]:
-                if mutualStartswith(code.lower(), noFixCode.lower()):
-                    return False
+        if (
+            self.__noFixCodes and
+            any(mutualStartswith(code.lower(), noFixCode.lower())
+                for noFixCode in [c.strip() for c in self.__noFixCodes])
+        ):
+            return False
 
         if self.__fixCodes:
-            for fixCode in [c.strip() for c in self.__fixCodes]:
-                if mutualStartswith(code.lower(), fixCode.lower()):
-                    return True
-            return False
+            return any(mutualStartswith(code.lower(), fixCode.lower())
+                       for fixCode in [c.strip() for c in self.__fixCodes])
 
         return True
     
@@ -2421,9 +2421,8 @@
 
                 if token_type == tokenize.OP and text in ']})':
                     pass
-                elif visual_indent is True:
-                    if not indent[depth]:
-                        indent[depth] = start[1]
+                elif visual_indent is True and not indent[depth]:
+                    indent[depth] = start[1]
 
             # line altered: comments shouldn't define a visual indent
             if parens[row] and not indent[depth] and token_type not in (
@@ -2884,10 +2883,12 @@
                 '[': ']',
                 '{': '}'}.get(lines[0][-1], None)
 
-            if len(lines) > 1:
-                if (badStartingSymbol and
-                        lines[1].lstrip().startswith(badStartingSymbol)):
-                    rank += 20
+            if (
+                len(lines) > 1 and
+                badStartingSymbol and
+                lines[1].lstrip().startswith(badStartingSymbol)
+            ):
+                rank += 20
 
             if re.match(r".*[+\-\*/] \($", lines[0]):
                 # "1 * (\n" is ugly as hell.
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/djangoXssVulnerability.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/djangoXssVulnerability.py	Sun Apr 11 16:53:48 2021 +0200
@@ -159,19 +159,23 @@
         @rtype bool
         """
         assigned = False
-        if self.__ignoreNodes:
-            if isinstance(self.__ignoreNodes, (list, tuple, object)):
-                if isinstance(node, self.__ignoreNodes):
-                    return assigned
+        if (
+            self.__ignoreNodes and
+            isinstance(self.__ignoreNodes, (list, tuple, object)) and
+            isinstance(node, self.__ignoreNodes)
+        ):
+            return assigned
         
         if isinstance(node, ast.Expr):
             assigned = self.isAssigned(node.value)
         elif isinstance(node, ast.FunctionDef):
             for name in node.args.args:
-                if isinstance(name, ast.Name):
-                    if name.id == self.var_name.id:
-                        # If is param the assignations are not affected
-                        return assigned
+                if (
+                    isinstance(name, ast.Name) and
+                    name.id == self.var_name.id
+                ):
+                    # If is param the assignations are not affected
+                    return assigned
             
             assigned = self.isAssignedIn(node.body)
         elif isinstance(node, ast.With):
@@ -194,10 +198,12 @@
             assigned = []
             assigned.extend(self.isAssignedIn(node.body))
             assigned.extend(self.isAssignedIn(node.orelse))
-        elif isinstance(node, ast.AugAssign):
-            if isinstance(node.target, ast.Name):
-                if node.target.id == self.__varName.id:
-                    assigned = node.value
+        elif (
+            isinstance(node, ast.AugAssign) and
+            isinstance(node.target, ast.Name) and
+            node.target.id == self.__varName.id
+        ):
+            assigned = node.value
         elif isinstance(node, ast.Assign) and node.targets:
             target = node.targets[0]
             if isinstance(target, ast.Name):
@@ -229,10 +235,11 @@
     """
     secure = False
     if isinstance(xssVar, ast.Name):
-        if isinstance(parent, ast.FunctionDef):
-            for name in parent.args.args:
-                if name.arg == xssVar.id:
-                    return False  # Params are not secure
+        if (
+            isinstance(parent, ast.FunctionDef) and
+            any(name.arg == xssVar.id for name in parent.args.args)
+        ):
+            return False  # Params are not secure
         
         analyser = DeepAssignation(xssVar, ignoreNodes)
         for node in parent.body:
@@ -288,14 +295,15 @@
     secure = False
     evaluate = False
     
-    if isinstance(call, ast.Call) and isinstance(call.func, ast.Attribute):
-        if (
-            AstUtilities.isString(call.func.value) and
-            call.func.attr == 'format'
-        ):
-            evaluate = True
-            if call.keywords:
-                evaluate = False
+    if (
+        isinstance(call, ast.Call) and
+        isinstance(call.func, ast.Attribute) and
+        AstUtilities.isString(call.func.value) and
+        call.func.attr == 'format'
+    ):
+        evaluate = True
+        if call.keywords:
+            evaluate = False
     
     if evaluate:
         args = list(call.args)
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py	Sun Apr 11 16:53:48 2021 +0200
@@ -309,10 +309,7 @@
             if not isinstance(argumentValues, list):
                 # if passed a single value, or a tuple, convert to a list
                 argumentValues = [argumentValues]
-            for val in argumentValues:
-                if argValue == val:
-                    return True
-            return False
+            return any(argValue == val for val in argumentValues)
         else:
             # argument name not found, return None to allow testing for this
             # eventuality
@@ -402,9 +399,7 @@
         @return flag indicating the given module was found
         @rtype bool
         """
-        if 'imports' in self.__context:
-            for imp in self.__context['imports']:
-                if module in imp:
-                    return True
-        
-        return False
+        try:
+            return any(module in imp for imp in self.__context['imports'])
+        except KeyError:
+            return False
--- a/eric6/Plugins/VcsPlugins/vcsPySvn/ProjectBrowserHelper.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsPySvn/ProjectBrowserHelper.py	Sun Apr 11 16:53:48 2021 +0200
@@ -984,7 +984,4 @@
         @param items items to check (list of QTreeWidgetItems)
         @return flag indicating items contain file type items (boolean)
         """
-        for itm in items:
-            if isinstance(itm, ProjectBrowserFileItem):
-                return True
-        return False
+        return any(isinstance(itm, ProjectBrowserFileItem) for itm in items)
--- a/eric6/Plugins/VcsPlugins/vcsSubversion/ProjectBrowserHelper.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsSubversion/ProjectBrowserHelper.py	Sun Apr 11 16:53:48 2021 +0200
@@ -967,7 +967,4 @@
         @param items items to check (list of QTreeWidgetItems)
         @return flag indicating items contain file type items (boolean)
         """
-        for itm in items:
-            if isinstance(itm, ProjectBrowserFileItem):
-                return True
-        return False
+        return any(isinstance(itm, ProjectBrowserFileItem) for itm in items)
--- a/eric6/Project/Project.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Project/Project.py	Sun Apr 11 16:53:48 2021 +0200
@@ -3762,11 +3762,13 @@
         """
         newfn = os.path.abspath(fn)
         newfn = self.getRelativePath(newfn)
-        for group in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS",
-                      "RESOURCES", "TRANSLATIONS", "OTHERS"]:
-            if newfn in self.pdata[group]:
-                return True
-        return False
+        return any(
+            newfn in self.pdata[group]
+            for group in [
+                "SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                "TRANSLATIONS", "OTHERS"
+            ]
+        )
     
     def isProjectFile(self, fn):
         """
@@ -3776,12 +3778,13 @@
         @param fn filename to be checked (string)
         @return flag indicating membership (boolean)
         """
-        for group in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS",
-                      "RESOURCES", "TRANSLATIONS", "OTHERS"]:
-            if self.__checkProjectFileGroup(fn, group):
-                return True
-        
-        return False
+        return any(
+            self.__checkProjectFileGroup(fn, group)
+            for group in [
+                "SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                "TRANSLATIONS", "OTHERS"
+            ]
+        )
         
     def __checkProjectFileGroup(self, fn, group):
         """
@@ -3797,20 +3800,18 @@
         if newfn in self.pdata[group]:
             return True
         elif group == "OTHERS":
-            for entry in self.pdata[group]:
-                if newfn.startswith(entry):
-                    return True
+            if any(newfn.startswith(entry) for entry in self.pdata[group]):
+                return True
         
         if Utilities.isWindowsPlatform():
             # try the above case-insensitive
             newfn = newfn.lower()
-            for entry in self.pdata[group]:
-                if entry.lower() == newfn:
-                    return True
+            if any(entry.lower() == newfn for entry in self.pdata[group]):
+                return True
         elif group == "OTHERS":
-            for entry in self.pdata[group]:
-                if newfn.startswith(entry.lower()):
-                    return True
+            if any(newfn.startswith(entry.lower())
+                   for entry in self.pdata[group]):
+                return True
         
         return False
         
--- a/eric6/QScintilla/DocstringGenerator/PyDocstringGenerator.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/QScintilla/DocstringGenerator/PyDocstringGenerator.py	Sun Apr 11 16:53:48 2021 +0200
@@ -481,11 +481,8 @@
         @return flag indicating the position is in between
         @rtype bool
         """
-        for posLeft, posRight in pairs:
-            if posLeft < posChar < posRight:
-                return True
-        
-        return False
+        return any(posLeft < posChar < posRight
+                   for (posLeft, posRight) in pairs)
     
     def __findQuotePosition(self, text):
         """
--- a/eric6/QScintilla/Editor.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/QScintilla/Editor.py	Sun Apr 11 16:53:48 2021 +0200
@@ -4942,11 +4942,7 @@
             return False
         
         wseps = self.lexer_.autoCompletionWordSeparators()
-        for wsep in wseps:
-            if wsep.endswith(ch):
-                return True
-        
-        return False
+        return any(wsep.endswith(ch) for wsep in wseps)
     
     def __autocompletionCancelled(self):
         """
--- a/eric6/Templates/TemplateViewer.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Templates/TemplateViewer.py	Sun Apr 11 16:53:48 2021 +0200
@@ -1059,11 +1059,8 @@
                 groups = []
         else:
             groups = list(self.groups.values())
-        for group in groups:
-            if group.hasEntry(entryName):
-                return True
         
-        return False
+        return any(group.hasEntry(entryName) for group in groups)
     
     def getTemplateNames(self, start, groupName=None):
         """
--- a/eric6/UI/Browser.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/UI/Browser.py	Sun Apr 11 16:53:48 2021 +0200
@@ -720,11 +720,9 @@
         """
         if filterList is None:
             filterList = self.selectedItemsFilter
-        for typ in filterList:
-            if isinstance(itm, typ):
-                return True
-        return False
         
+        return any(isinstance(itm, typ) for typ in filterList)
+    
     def getSelectedItems(self, filterList=None):
         """
         Public method to get the selected items.
--- a/eric6/UI/LogView.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/UI/LogView.py	Sun Apr 11 16:53:48 2021 +0200
@@ -177,11 +177,8 @@
             filters = self.__stderrFilter + self.__stdxxxFilter
         else:
             filters = self.__stdoutFilter + self.__stdxxxFilter
-        for msgFilter in filters:
-            if msgFilter in message:
-                return True
         
-        return False
+        return any(msgFilter in message for msgFilter in filters)
         
     def appendToStdout(self, txt):
         """
--- a/eric6/Utilities/__init__.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/Utilities/__init__.py	Sun Apr 11 16:53:48 2021 +0200
@@ -267,14 +267,17 @@
     except (UnicodeError, LookupError):
         pass
     
-    if Preferences.getEditor("AdvancedEncodingDetection"):
-        # Use the guessed one even if confifence level is low
-        if guess and guess['encoding'] is not None:
-            try:
-                codec = guess['encoding'].lower()
-                return str(text, codec), '{0}-guessed'.format(codec)
-            except (UnicodeError, LookupError):
-                pass
+    if (
+        Preferences.getEditor("AdvancedEncodingDetection") and
+        guess and
+        guess['encoding'] is not None
+    ):
+        # Use the guessed one even if confidence level is low
+        try:
+            codec = guess['encoding'].lower()
+            return str(text, codec), '{0}-guessed'.format(codec)
+        except (UnicodeError, LookupError):
+            pass
     
     # Assume UTF-8 loosing information
     return str(text, "utf-8", "ignore"), 'utf-8-ignore'
@@ -629,10 +632,7 @@
     @return dictionary of string, boolean, complex, float and int
     """
     flags = {}
-    if isinstance(text, str):
-        lines = text.rstrip().splitlines()
-    else:
-        lines = text
+    lines = text.rstrip().splitlines() if isinstance(text, str) else text
     for line in reversed(lines):
         try:
             index = line.index("eflag:")
@@ -823,11 +823,8 @@
         return False
     
     dirs = path.split(os.pathsep)
-    for directory in dirs:
-        if os.access(os.path.join(directory, file), os.X_OK):
-            return True
-    
-    return False
+    return any(os.access(os.path.join(directory, file), os.X_OK)
+               for directory in dirs)
 
 
 def startswithPath(path, start):
@@ -908,9 +905,8 @@
             return ""
         
     cur_path = os.path.join(os.curdir, file)
-    if os.path.exists(cur_path):
-        if os.access(cur_path, os.X_OK):
-            return cur_path
+    if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
+        return cur_path
 
     path = os.getenv('PATH')
     
@@ -945,9 +941,8 @@
             return []
         
     cur_path = os.path.join(os.curdir, file)
-    if os.path.exists(cur_path):
-        if os.access(cur_path, os.X_OK):
-            paths.append(cur_path)
+    if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
+        paths.append(cur_path)
 
     path = os.getenv('PATH')
     
@@ -986,9 +981,8 @@
     
     for filename in filenames:
         cur_path = os.path.join(os.curdir, filename)
-        if os.path.exists(cur_path):
-            if os.access(cur_path, os.X_OK):
-                return os.path.abspath(cur_path)
+        if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
+            return os.path.abspath(cur_path)
 
     path = os.getenv('PATH')
     
@@ -1166,10 +1160,7 @@
     @return list of all files and directories in the tree rooted
         at path. The names are expanded to start with path.
     """
-    if filesonly:
-        files = []
-    else:
-        files = [path]
+    files = [] if filesonly else [path]
     try:
         entries = os.listdir(path)
         for entry in entries:
@@ -1479,9 +1470,8 @@
     """
     user = getpass.getuser()
     
-    if isWindowsPlatform():
-        if not user:
-            return win32_GetUserName()
+    if isWindowsPlatform() and not user:
+        return win32_GetUserName()
     
     return user
 
@@ -1601,11 +1591,11 @@
                 line0 = source.splitlines()[0]
             else:
                 line0 = source[0]
-            if line0.startswith("#!"):
-                if "python3" in line0:
-                    pyVer = 3
-                elif "python" in line0:
-                    pyVer = 3
+            if (
+                line0.startswith("#!") and
+                (("python3" in line0) or ("python" in line0))
+            ):
+                pyVer = 3
         
         if pyVer == 0 and ext in py3Ext:
             pyVer = 3
@@ -1858,11 +1848,7 @@
     proc.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels)
     proc.start(interpreter, args)
     finished = proc.waitForFinished(30000)
-    if finished:
-        if proc.exitCode() == 0:
-            return True
-    
-    return False
+    return finished and proc.exitCode() == 0
 
 ###############################################################################
 # Other utility functions below
@@ -1887,10 +1873,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"
     
     info = ["Version Numbers:"]
     
@@ -2022,17 +2005,16 @@
     proc.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels)
     proc.start(interpreter, args)
     finished = proc.waitForFinished(30000)
-    if finished:
-        if proc.exitCode() == 0:
-            text = proc.readAllStandardOutput()
-            sysPathResult = str(text, "utf-8", "replace").strip()
-            try:
-                sysPath = json.loads(sysPathResult)
-                if "" in sysPath:
-                    sysPath.remove("")
-            except (TypeError, ValueError):
-                # ignore faulty results and return empty list
-                pass
+    if finished and proc.exitCode() == 0:
+        text = proc.readAllStandardOutput()
+        sysPathResult = str(text, "utf-8", "replace").strip()
+        try:
+            sysPath = json.loads(sysPathResult)
+            if "" in sysPath:
+                sysPath.remove("")
+        except (TypeError, ValueError):
+            # ignore faulty results and return empty list
+            pass
     
     return sysPath
 
--- a/eric6/WebBrowser/AdBlock/AdBlockMatcher.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/WebBrowser/AdBlock/AdBlockMatcher.py	Sun Apr 11 16:53:48 2021 +0200
@@ -80,11 +80,7 @@
         @return flag indicating disabled state
         @rtype bool
         """
-        for rule in self.__documentRules:
-            if rule.urlMatch(url):
-                return True
-        
-        return False
+        return any(rule.urlMatch(url) for rule in self.__documentRules)
     
     def elemHideDisabledForUrl(self, url):
         """
@@ -99,11 +95,7 @@
         if self.adBlockDisabledForUrl(url):
             return True
         
-        for rule in self.__elemhideRules:
-            if rule.urlMatch(url):
-                return True
-        
-        return False
+        return any(rule.urlMatch(url) for rule in self.__elemhideRules)
     
     def elementHidingRules(self):
         """
--- a/eric6/WebBrowser/Feeds/FeedsManager.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/WebBrowser/Feeds/FeedsManager.py	Sun Apr 11 16:53:48 2021 +0200
@@ -91,9 +91,8 @@
             self.__load()
         
         # step 1: check, if feed was already added
-        for feed in self.__feeds:
-            if feed[0] == urlString:
-                return False
+        if any(feed[0] == urlString for feed in self.__feeds):
+            return False
         
         # step 2: add the feed
         if icon.isNull():
--- a/eric6/WebBrowser/GreaseMonkey/GreaseMonkeyManager.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/WebBrowser/GreaseMonkey/GreaseMonkeyManager.py	Sun Apr 11 16:53:48 2021 +0200
@@ -206,11 +206,7 @@
         @param fullName full name of the script (string)
         @return flag indicating the existence (boolean)
         """
-        for script in self.__scripts:
-            if script.fullName() == fullName:
-                return True
-        
-        return False
+        return any(script.fullName() == fullName for script in self.__scripts)
     
     def enableScript(self, script):
         """
--- a/eric6/WebBrowser/Tools/WebBrowserTools.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/WebBrowser/Tools/WebBrowserTools.py	Sun Apr 11 16:53:48 2021 +0200
@@ -63,11 +63,7 @@
     @return flag indicating the presence of at least one whitespace character
     @rtype bool
     """
-    for ch in string:
-        if ch.isspace():
-            return True
-    
-    return False
+    return any(ch.isspace() for ch in string)
 
 
 def ensureUniqueFilename(name, appendFormat="({0})"):
--- a/eric6/WebBrowser/WebBrowserPage.py	Sun Apr 11 12:38:16 2021 +0200
+++ b/eric6/WebBrowser/WebBrowserPage.py	Sun Apr 11 16:53:48 2021 +0200
@@ -138,9 +138,11 @@
             return False
         
         # AdBlock
-        if url.scheme() == "abp":
-            if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url):
-                return False
+        if (
+            url.scheme() == "abp" and
+            WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url)
+        ):
+            return False
         
         # GreaseMonkey
         try:
@@ -565,10 +567,10 @@
                 "})()",
                 WebBrowserPage.SafeJsWorld
             )
-            if pos is not None:
-                pos = QPointF(pos["x"], pos["y"])
-            else:
-                pos = QPointF(0.0, 0.0)
+            pos = (
+                QPointF(0.0, 0.0) if pos is None
+                else QPointF(pos["x"], pos["y"])
+            )
             
             return pos
     
@@ -726,12 +728,7 @@
             Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
         for server in certificateDict:
             localCAList = QSslCertificate.fromData(certificateDict[server])
-            for cert in certList:
-                if cert in localCAList:
-                    return True
+            if any(cert in localCAList for cert in certList):
+                return True
         
-        for cert in certList:
-            if cert.isBlacklisted():
-                return False
-        
-        return True
+        return all(not cert.isBlacklisted() for cert in certList)

eric ide

mercurial