From 3ea92736b8c7465e68598da1b735f6fe0389f804 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Tue, 20 Apr 2021 22:25:23 -0700 Subject: [PATCH] Do not use list comprehensions with any or all python any and all are able to break early the moment they come across a member of the iterable that meets the condition; but having a list comprehension nested within breaks that ability to exit early, as the list comprehension has to finish being constructed first before it can be evaluated --- pyqtgraph/debug.py | 4 ++-- pyqtgraph/dockarea/Container.py | 2 +- pyqtgraph/imageview/ImageView.py | 2 +- pyqtgraph/metaarray/MetaArray.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyqtgraph/debug.py b/pyqtgraph/debug.py index 15d1fb3c..37b612cd 100644 --- a/pyqtgraph/debug.py +++ b/pyqtgraph/debug.py @@ -202,7 +202,7 @@ def findRefPath(startObj, endObj, maxLen=8, restart=True, seen={}, path=None, ig #print prefix+" FRAME" continue try: - if any([r is x for x in path]): + if any(r is x for x in path): #print prefix+" LOOP", objChainString([r]+path) continue except: @@ -282,7 +282,7 @@ def refPathString(chain): o2 = chain[i] cont = False if isinstance(o1, list) or isinstance(o1, tuple): - if any([o2 is x for x in o1]): + if any(o2 is x for x in o1): s += "[%d]" % o1.index(o2) continue #print " not list" diff --git a/pyqtgraph/dockarea/Container.py b/pyqtgraph/dockarea/Container.py index 04b775f9..34f16288 100644 --- a/pyqtgraph/dockarea/Container.py +++ b/pyqtgraph/dockarea/Container.py @@ -126,7 +126,7 @@ class SplitContainer(Container, QtGui.QSplitter): def saveState(self): sizes = self.sizes() - if all([x == 0 for x in sizes]): + if all(x == 0 for x in sizes): sizes = [10] * len(sizes) return {'sizes': sizes} diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index c7f0b66d..6f60170c 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -274,7 +274,7 @@ class ImageView(QtGui.QWidget): if not isinstance(img, np.ndarray): required = ['dtype', 'max', 'min', 'ndim', 'shape', 'size'] - if not all([hasattr(img, attr) for attr in required]): + if not all(hasattr(img, attr) for attr in required): raise TypeError("Image must be NumPy array or any object " "that provides compatible attributes/methods:\n" " %s" % str(required)) diff --git a/pyqtgraph/metaarray/MetaArray.py b/pyqtgraph/metaarray/MetaArray.py index 169ff43c..b07f66ab 100644 --- a/pyqtgraph/metaarray/MetaArray.py +++ b/pyqtgraph/metaarray/MetaArray.py @@ -124,7 +124,7 @@ class MetaArray(object): nameTypes = [basestring, tuple] @staticmethod def isNameType(var): - return any([isinstance(var, t) for t in MetaArray.nameTypes]) + return any(isinstance(var, t) for t in MetaArray.nameTypes) ## methods to wrap from embedded ndarray / HDF5