From 03ea36845443451407b1381e6d9c36be5a706375 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Tue, 20 Apr 2021 23:40:03 -0700 Subject: [PATCH] Clean up Errors for CodeQL analyzer CodeQL identified some errors and warnings, which this commit cleans up. --- examples/GLIsosurface.py | 2 -- examples/GLVolumeItem.py | 3 --- pyqtgraph/Point.py | 1 + pyqtgraph/Vector.py | 1 - pyqtgraph/canvas/CanvasItem.py | 3 +-- pyqtgraph/functions.py | 3 --- pyqtgraph/graphicsItems/CurvePoint.py | 1 - pyqtgraph/graphicsItems/ROI.py | 28 ++++++++++------------ pyqtgraph/graphicsItems/TargetItem.py | 3 +-- pyqtgraph/graphicsItems/ViewBox/ViewBox.py | 1 - pyqtgraph/imageview/ImageView.py | 2 +- pyqtgraph/opengl/GLViewWidget.py | 2 +- pyqtgraph/parametertree/SystemSolver.py | 5 ---- pyqtgraph/widgets/GraphicsView.py | 3 --- 14 files changed, 17 insertions(+), 41 deletions(-) diff --git a/examples/GLIsosurface.py b/examples/GLIsosurface.py index 0f773885..1afe797c 100644 --- a/examples/GLIsosurface.py +++ b/examples/GLIsosurface.py @@ -8,7 +8,6 @@ This example uses the isosurface function to convert a scalar field import initExample import numpy as np -from pyqtgraph.Qt import QtCore, QtGui import pyqtgraph as pg import pyqtgraph.opengl as gl @@ -29,7 +28,6 @@ def psi(i, j, k, offset=(25, 25, 50)): y = j-offset[1] z = k-offset[2] th = np.arctan2(z, np.hypot(x, y)) - phi = np.arctan2(y, x) r = np.sqrt(x**2 + y**2 + z **2) a0 = 1 ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1) diff --git a/examples/GLVolumeItem.py b/examples/GLVolumeItem.py index 99856a00..ba67514b 100644 --- a/examples/GLVolumeItem.py +++ b/examples/GLVolumeItem.py @@ -9,7 +9,6 @@ import initExample import numpy as np import pyqtgraph as pg -from pyqtgraph.Qt import QtCore, QtGui import pyqtgraph.opengl as gl from pyqtgraph import functions as fn @@ -31,10 +30,8 @@ def psi(i, j, k, offset=(50,50,100)): y = j-offset[1] z = k-offset[2] th = np.arctan2(z, np.hypot(x, y)) - phi = np.arctan2(y, x) r = np.sqrt(x**2 + y**2 + z **2) a0 = 2 - #ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th) ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1) return ps diff --git a/pyqtgraph/Point.py b/pyqtgraph/Point.py index 6f56a035..bdd8bc33 100644 --- a/pyqtgraph/Point.py +++ b/pyqtgraph/Point.py @@ -8,6 +8,7 @@ Distributed under MIT/X11 license. See license.txt for more information. from .Qt import QtCore from math import atan2, hypot, degrees + class Point(QtCore.QPointF): """Extension of QPointF which adds a few missing methods.""" diff --git a/pyqtgraph/Vector.py b/pyqtgraph/Vector.py index 2c838d64..a64e8968 100644 --- a/pyqtgraph/Vector.py +++ b/pyqtgraph/Vector.py @@ -7,7 +7,6 @@ Distributed under MIT/X11 license. See license.txt for more information. from math import acos, degrees from .Qt import QtGui, QtCore, QT_LIB from . import functions as fn -import numpy as np class Vector(QtGui.QVector3D): """Extension of QVector3D which adds a few helpful methods.""" diff --git a/pyqtgraph/canvas/CanvasItem.py b/pyqtgraph/canvas/CanvasItem.py index 0cd86d0e..3883919e 100644 --- a/pyqtgraph/canvas/CanvasItem.py +++ b/pyqtgraph/canvas/CanvasItem.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np -from ..Qt import QtGui, QtCore, QtSvg, QT_LIB +from ..Qt import QtGui, QtCore, QT_LIB from .. import functions as fn from ..graphicsItems.ROI import ROI from .. import SRTTransform, ItemGroup diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index abbd77d1..45043a4c 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -67,10 +67,8 @@ def siScale(x, minVal=1e-25, allowUnicode=True): raise if abs(x) < minVal: m = 0 - x = 0 else: m = int(clip_scalar(math.floor(math.log(abs(x))/math.log(1000)), -9.0, 9.0)) - if m == 0: pref = '' elif m < -8 or m > 8: @@ -82,7 +80,6 @@ def siScale(x, minVal=1e-25, allowUnicode=True): pref = SI_PREFIXES_ASCII[m+8] m1 = -3*m p = 10.**m1 - return (p, pref) diff --git a/pyqtgraph/graphicsItems/CurvePoint.py b/pyqtgraph/graphicsItems/CurvePoint.py index 66117165..c7052ddb 100644 --- a/pyqtgraph/graphicsItems/CurvePoint.py +++ b/pyqtgraph/graphicsItems/CurvePoint.py @@ -2,7 +2,6 @@ from math import atan2, degrees from ..Qt import QtGui, QtCore from . import ArrowItem from ..functions import clip_scalar -import numpy as np from ..Point import Point import weakref from .GraphicsObject import GraphicsObject diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index 08ff0480..6c5f8418 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -15,9 +15,9 @@ of how to build an ROI at the bottom of the file. from ..Qt import QtCore, QtGui import numpy as np #from numpy.linalg import norm -from ..Point import * +from ..Point import Point from ..SRTTransform import SRTTransform -from math import atan2, cos, sin, hypot, radians, degrees +from math import atan2, cos, sin, hypot, radians from .. import functions as fn from .GraphicsObject import GraphicsObject from .UIGraphicsItem import UIGraphicsItem @@ -141,12 +141,13 @@ class ROI(GraphicsObject): maxBounds=None, snapSize=1.0, scaleSnap=False, translateSnap=False, rotateSnap=False, parent=None, pen=None, hoverPen=None, handlePen=None, handleHoverPen=None, - movable=True, rotatable=True, resizable=True, removable=False): + movable=True, rotatable=True, resizable=True, removable=False, + aspectLocked=False): GraphicsObject.__init__(self, parent) self.setAcceptedMouseButtons(QtCore.Qt.NoButton) pos = Point(pos) size = Point(size) - self.aspectLocked = False + self.aspectLocked = aspectLocked self.translatable = movable self.rotatable = rotatable self.resizable = resizable @@ -678,7 +679,7 @@ class ROI(GraphicsObject): The format returned is a list of (name, pos) tuples. """ - if index == None: + if index is None: positions = [] for h in self.handles: positions.append((h['name'], h['pos'])) @@ -691,7 +692,7 @@ class ROI(GraphicsObject): The format returned is a list of (name, pos) tuples. """ - if index == None: + if index is None: positions = [] for h in self.handles: positions.append((h['name'], h['item'].scenePos())) @@ -1298,7 +1299,7 @@ class ROI(GraphicsObject): """Return global transformation (rotation angle+translation) required to move from relative state to current state. If relative state isn't specified, then we use the state of the ROI when mouse is pressed.""" - if relativeTo == None: + if relativeTo is None: relativeTo = self.preMoveState st = self.getState() @@ -1941,8 +1942,7 @@ class CircleROI(EllipseROI): if radius is None: raise TypeError("Must provide either size or radius.") size = (radius*2, radius*2) - EllipseROI.__init__(self, pos, size, **args) - self.aspectLocked = True + EllipseROI.__init__(self, pos, size, aspectLocked=True, **args) def _addHandles(self): self.addScaleHandle([0.5*2.**-0.5 + 0.5, 0.5*2.**-0.5 + 0.5], [0.5, 0.5]) @@ -2307,16 +2307,15 @@ class CrosshairROI(ROI): """A crosshair ROI whose position is at the center of the crosshairs. By default, it is scalable, rotatable and translatable.""" def __init__(self, pos=None, size=None, **kargs): - if size == None: + if size is None: size=[1,1] - if pos == None: + if pos is None: pos = [0,0] self._shape = None - ROI.__init__(self, pos, size, **kargs) + ROI.__init__(self, pos, size, aspectLocked=True, **kargs) self.sigRegionChanged.connect(self.invalidate) self.addScaleRotateHandle(Point(1, 0), Point(0, 0)) - self.aspectLocked = True def invalidate(self): self._shape = None @@ -2391,9 +2390,6 @@ class TriangleROI(ROI): """ def __init__(self, pos, size, **args): - ROI.__init__(self, pos, [size, size], **args) - self.aspectLocked = True - angles = np.linspace(0, pi * 4 / 3, 3) ROI.__init__(self, pos, [size, size], aspectLocked=True, **args) angles = np.linspace(0, np.pi * 4 / 3, 3) verticies = (np.array((np.sin(angles), np.cos(angles))).T + 1.0) / 2.0 diff --git a/pyqtgraph/graphicsItems/TargetItem.py b/pyqtgraph/graphicsItems/TargetItem.py index 40fcdfc0..1a4d5144 100644 --- a/pyqtgraph/graphicsItems/TargetItem.py +++ b/pyqtgraph/graphicsItems/TargetItem.py @@ -1,5 +1,4 @@ -from math import atan2, pi, degrees - +from math import atan2 from ..Qt import QtGui, QtCore from ..Point import Point from .. import functions as fn diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index ac771c1c..8d60c577 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -550,7 +550,6 @@ class ViewBox(GraphicsWidget): dy = 1 mn -= dy*0.5 mx += dy*0.5 - xpad = 0.0 # Make sure no nan/inf get through if not math.isfinite(mn) or not math.isfinite(mx): diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 6f60170c..f934b36d 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -12,7 +12,7 @@ Widget used for displaying 2D or 3D data. Features: - ROI plotting - Image normalization through a variety of methods """ -import os, sys +import os from math import log10 import numpy as np diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index 0f380ec9..a309d7a0 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -5,7 +5,7 @@ import numpy as np from .. import Vector from .. import functions as fn import warnings -from math import cos, sin, tan, degrees, radians +from math import cos, sin, tan, radians ##Vector = QtGui.QVector3D ShareWidget = None diff --git a/pyqtgraph/parametertree/SystemSolver.py b/pyqtgraph/parametertree/SystemSolver.py index de177a37..d7b6bef8 100644 --- a/pyqtgraph/parametertree/SystemSolver.py +++ b/pyqtgraph/parametertree/SystemSolver.py @@ -398,9 +398,6 @@ if __name__ == '__main__': # value at the same time. sh = (1./60.) raise - - - return ap def _balance(self): @@ -408,8 +405,6 @@ if __name__ == '__main__': light = self.lightMeter sh = self.shutter ap = self.aperture - fl = self.flash - bal = (4.0 / ap) * (sh / (1./60.)) * (iso / 100.) * (2 ** light) return log2(bal) diff --git a/pyqtgraph/widgets/GraphicsView.py b/pyqtgraph/widgets/GraphicsView.py index 56304f51..d2b0f553 100644 --- a/pyqtgraph/widgets/GraphicsView.py +++ b/pyqtgraph/widgets/GraphicsView.py @@ -7,10 +7,7 @@ Distributed under MIT/X11 license. See license.txt for more information. from ..Qt import QtCore, QtGui, QtWidgets, QT_LIB from ..Point import Point -import sys, os -from .FileDialog import FileDialog from ..GraphicsScene import GraphicsScene -import numpy as np from .. import functions as fn from .. import debug as debug from .. import getConfigOption