From 1bc33025d6db282fdea84026316a6197255c463b Mon Sep 17 00:00:00 2001 From: "luz.paz" Date: Tue, 22 Oct 2019 10:42:18 -0400 Subject: [PATCH] LGTM: various fixes for using string operator instead of numeric --- src/Mod/Part/JoinFeatures.py | 2 +- src/Mod/Part/MakeBottle.py | 2 +- src/Mod/PartDesign/FeatureHole/FeatureHole.py | 8 ++++---- src/Mod/PartDesign/FeatureHole/HoleGui.py | 4 ++-- src/Mod/PartDesign/FeatureHole/TaskHole.py | 4 ++-- src/Mod/PartDesign/Scripts/DistanceBolt.py | 3 +-- src/Mod/PartDesign/Scripts/Epitrochoid.py | 2 +- src/Mod/PartDesign/Scripts/Gear.py | 4 ++-- src/Mod/PartDesign/Scripts/Parallelepiped.py | 4 ++-- src/Mod/PartDesign/Scripts/Spring.py | 2 +- src/Mod/PartDesign/WizardShaft/Shaft.py | 10 +++++----- src/Mod/PartDesign/WizardShaft/WizardShaft.py | 2 +- .../PartDesign/WizardShaft/WizardShaftTable.py | 2 +- src/Mod/Path/PathScripts/PathAdaptive.py | 2 +- src/Mod/Path/PathScripts/PathSimulatorGui.py | 2 +- src/Mod/Robot/RobotExample.py | 3 +-- src/Mod/Sandbox/exportDRAWEXE.py | 2 +- src/Mod/Sketcher/SketcherExample.py | 4 +--- src/Mod/Spreadsheet/App/Spreadsheet_legacy.py | 10 +++++----- src/Mod/Spreadsheet/importXLSX.py | 4 ++-- src/Mod/TemplatePyMod/Commands.py | 4 ++-- src/Mod/Test/Document.py | 18 +++++++++--------- src/Tools/updatefromcrowdin.py | 5 ++--- 23 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/Mod/Part/JoinFeatures.py b/src/Mod/Part/JoinFeatures.py index ffa74492b457..f2e3b70c4f6d 100644 --- a/src/Mod/Part/JoinFeatures.py +++ b/src/Mod/Part/JoinFeatures.py @@ -123,7 +123,7 @@ def __init__(self,vobj): vobj.Proxy = self def getIcon(self): - if self.Object == None: + if self.Object is None: return getIconPath("Part_JoinConnect.svg") else: return getIconPath( { diff --git a/src/Mod/Part/MakeBottle.py b/src/Mod/Part/MakeBottle.py index 22b14ef25629..9876aafbb04c 100644 --- a/src/Mod/Part/MakeBottle.py +++ b/src/Mod/Part/MakeBottle.py @@ -67,7 +67,7 @@ def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0): def makeBoreHole(): # create a document if needed - if App.ActiveDocument == None: + if App.ActiveDocument is None: App.newDocument("Solid") Group = App.ActiveDocument.addObject("App::DocumentObjectGroup","Group") diff --git a/src/Mod/PartDesign/FeatureHole/FeatureHole.py b/src/Mod/PartDesign/FeatureHole/FeatureHole.py index b3b14b35df62..bf27eb8e425d 100644 --- a/src/Mod/PartDesign/FeatureHole/FeatureHole.py +++ b/src/Mod/PartDesign/FeatureHole/FeatureHole.py @@ -101,7 +101,7 @@ def execute(self, feature): def onChanged(self, fp, prop): #self.App.Console.PrintMessage("Change property: " + str(prop) + "\n") - if fp == None or fp.Support == None: + if fp is None or fp.Support is None: return if (prop == "HoleType" or prop == "Threaded" or prop == "Counterbore" or prop == "Countersink" @@ -116,7 +116,7 @@ def onChanged(self, fp, prop): def executePositionChanged(self, fp): "Change the position of the hole" - if fp.Support == None: + if fp.Support is None: return plane = self.feature.HoleGroove.Sketch.Support[0] # Get support (face) @@ -134,7 +134,7 @@ def executePositionChanged(self, fp): firstLine = None for e in wire.Edges: if type(e.Curve) == Part.LineSegment: - if firstLine == None: + if firstLine is None: firstLine = e firstDirection = e.Curve.EndPoint - e.Curve.StartPoint else: @@ -274,7 +274,7 @@ def setHoleDirection(self, feature): def executeSketchChanged(self, fp): "Change the sketch shape of the hole" - if self.feature.HoleGroove == None: + if self.feature.HoleGroove is None: return if fp.HoleType == "Thru": # TODO: Make this more stable diff --git a/src/Mod/PartDesign/FeatureHole/HoleGui.py b/src/Mod/PartDesign/FeatureHole/HoleGui.py index 60bcce50b084..8c909c3486da 100644 --- a/src/Mod/PartDesign/FeatureHole/HoleGui.py +++ b/src/Mod/PartDesign/FeatureHole/HoleGui.py @@ -46,7 +46,7 @@ def Activated(self): # Get active document doc = FreeCAD.activeDocument() - if doc == None: + if doc is None: QtGui.QMessageBox.critical(mw, "No document", "A document must be open in order to create a hole feature") return @@ -62,7 +62,7 @@ def Activated(self): # Show feature preview body = FreeCADGui.activeView().getActiveObject("pdbody"); - if body == None: + if body is None: QtGui.QMessageBox.critical(mw, "No active body", "Please create a body or make a body active") feature = doc.addObject("Part::FeaturePython","Hole") diff --git a/src/Mod/PartDesign/FeatureHole/TaskHole.py b/src/Mod/PartDesign/FeatureHole/TaskHole.py index 1a8ab9ccb732..f0389ffb65a2 100644 --- a/src/Mod/PartDesign/FeatureHole/TaskHole.py +++ b/src/Mod/PartDesign/FeatureHole/TaskHole.py @@ -94,7 +94,7 @@ def getMainWindow(self): def setupUi(self): mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskHole") - if form == None: + if form is None: return form.tabWidget = form.findChild(QtGui.QTabWidget, "tabWidget") # Type @@ -367,7 +367,7 @@ def updateUI(self): self.form.spinThreadLength.setValue(self.feature.ThreadLength) # Position self.form.buttonSupport.setText("Face") - if self.feature.Support == None: + if self.feature.Support is None: # First-time initialization selection = FreeCADGui.Selection.getSelectionEx() self.feature.Support = (selection[0].Object, selection[0].SubElementNames) diff --git a/src/Mod/PartDesign/Scripts/DistanceBolt.py b/src/Mod/PartDesign/Scripts/DistanceBolt.py index d2b7f72d7899..a7eece80cc99 100644 --- a/src/Mod/PartDesign/Scripts/DistanceBolt.py +++ b/src/Mod/PartDesign/Scripts/DistanceBolt.py @@ -56,10 +56,9 @@ def execute(self, fp): def makeDistanceBolt(): doc = FreeCAD.activeDocument() - if doc == None: + if doc is None: doc = FreeCAD.newDocument() bolt=doc.addObject("Part::FeaturePython","Distance_Bolt") bolt.Label = "Distance bolt" DistanceBolt(bolt) bolt.ViewObject.Proxy=0 - diff --git a/src/Mod/PartDesign/Scripts/Epitrochoid.py b/src/Mod/PartDesign/Scripts/Epitrochoid.py index 19e6b067cde7..b99094fb85d7 100644 --- a/src/Mod/PartDesign/Scripts/Epitrochoid.py +++ b/src/Mod/PartDesign/Scripts/Epitrochoid.py @@ -57,7 +57,7 @@ def execute(self, fp): #main part of script def makeEpitrochoid(): doc = FreeCAD.activeDocument() - if doc == None: + if doc is None: doc = FreeCAD.newDocument() epitrochoid=doc.addObject("Part::FeaturePython","Epitrochoid") #add object to document epitrochoid.Label = "Epitrochoid" diff --git a/src/Mod/PartDesign/Scripts/Gear.py b/src/Mod/PartDesign/Scripts/Gear.py index ee566713b5d6..46a0f71c261d 100644 --- a/src/Mod/PartDesign/Scripts/Gear.py +++ b/src/Mod/PartDesign/Scripts/Gear.py @@ -17,8 +17,8 @@ def proceed(): def compute(): QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) - - if FreeCAD.ActiveDocument==None: + + if FreeCAD.ActiveDocument is None: FreeCAD.newDocument("Gear") oldDocumentObjects=App.ActiveDocument.Objects diff --git a/src/Mod/PartDesign/Scripts/Parallelepiped.py b/src/Mod/PartDesign/Scripts/Parallelepiped.py index 3e2fda962948..37192171e2ce 100644 --- a/src/Mod/PartDesign/Scripts/Parallelepiped.py +++ b/src/Mod/PartDesign/Scripts/Parallelepiped.py @@ -64,7 +64,7 @@ def execute(self, fp): def makeParallelepiped(): doc = FreeCAD.activeDocument() - if doc == None: + if doc is None: doc = FreeCAD.newDocument() obj=doc.addObject("Part::FeaturePython","Parallelepiped") obj.Label = "Parallelepiped" @@ -74,7 +74,7 @@ def makeParallelepiped(): def makeBoxCylinder(): doc = FreeCAD.activeDocument() - if doc == None: + if doc is None: doc = FreeCAD.newDocument() cyl=doc.addObject("Part::Cylinder","Cylinder") cyl.Radius=16.0 diff --git a/src/Mod/PartDesign/Scripts/Spring.py b/src/Mod/PartDesign/Scripts/Spring.py index d9628961d78d..0018c166ef07 100644 --- a/src/Mod/PartDesign/Scripts/Spring.py +++ b/src/Mod/PartDesign/Scripts/Spring.py @@ -39,7 +39,7 @@ def execute(self, fp): def makeMySpring(): doc = FreeCAD.activeDocument() - if doc == None: + if doc is None: doc = FreeCAD.newDocument() spring=doc.addObject("Part::FeaturePython","My_Spring") spring.Label = "My Spring" diff --git a/src/Mod/PartDesign/WizardShaft/Shaft.py b/src/Mod/PartDesign/WizardShaft/Shaft.py index c519b97c37be..e23949e27c5d 100644 --- a/src/Mod/PartDesign/WizardShaft/Shaft.py +++ b/src/Mod/PartDesign/WizardShaft/Shaft.py @@ -213,7 +213,7 @@ def showDiagram(self, which): if which in self.Fstr: ax = self.Fstr.index(which) text = self.Qstrings[ax] - if self.F[ax] == None: + if self.F[ax] is None: # No data return if self.F[ax].name in self.diagrams: @@ -226,7 +226,7 @@ def showDiagram(self, which): elif which in self.Mstr: ax = self.Mstr.index(which) text = self.Mstrings[ax] - if self.M[ax] == None: + if self.M[ax] is None: # No data return if self.M[ax].name in self.diagrams: @@ -239,7 +239,7 @@ def showDiagram(self, which): elif which in self.wstr: ax = self.wstr.index(which) text = self.wstrings[ax] - if self.w[ax] == None: + if self.w[ax] is None: # No data return if self.w[ax].name in self.diagrams: @@ -252,7 +252,7 @@ def showDiagram(self, which): elif which in self.sigmaNstr: ax = self.sigmaNstr.index(which) text = self.sigmaNstrings[ax] - if self.sigmaN[ax] == None: + if self.sigmaN[ax] is None: # No data return if self.sigmaN[ax].name in self.diagrams: @@ -265,7 +265,7 @@ def showDiagram(self, which): elif which in self.sigmaBstr: ax = self.sigmaBstr.index(which) text = self.sigmaBstrings[ax] - if self.sigmaB[ax] == None: + if self.sigmaB[ax] is None: # No data return if self.sigmaB[ax].name in self.diagrams: diff --git a/src/Mod/PartDesign/WizardShaft/WizardShaft.py b/src/Mod/PartDesign/WizardShaft/WizardShaft.py index e555dd35d805..a8d49fe987fb 100644 --- a/src/Mod/PartDesign/WizardShaft/WizardShaft.py +++ b/src/Mod/PartDesign/WizardShaft/WizardShaft.py @@ -39,7 +39,7 @@ def __init__(self, doc): # Get active document or create a new one # Important because when setting the default data in WizardShaftTable() the # updateSketch() slot will be activated and it relies on finding a valid document - if self.doc == None: + if self.doc is None: self.Gui.activateWorkbench("PartDesignWorkbench") self.doc = self.App.newDocument() # Grab the newly created feature window diff --git a/src/Mod/PartDesign/WizardShaft/WizardShaftTable.py b/src/Mod/PartDesign/WizardShaft/WizardShaftTable.py index 2bfc3665e3db..c118a2d509e8 100644 --- a/src/Mod/PartDesign/WizardShaft/WizardShaftTable.py +++ b/src/Mod/PartDesign/WizardShaft/WizardShaftTable.py @@ -198,7 +198,7 @@ def slotValueChanged(self, value): self.editedValue = value def slotEditingFinished(self): - if self.editedRow == None: + if self.editedRow is None: return rowName = self.rowDictReverse[self.editedRow] if rowName is None: diff --git a/src/Mod/Path/PathScripts/PathAdaptive.py b/src/Mod/Path/PathScripts/PathAdaptive.py index 75814b66cd13..d7d3c575c1b8 100644 --- a/src/Mod/Path/PathScripts/PathAdaptive.py +++ b/src/Mod/Path/PathScripts/PathAdaptive.py @@ -422,7 +422,7 @@ def progressFn(tpaths): start = time.time() - if inputStateChanged or adaptiveResults == None: + if inputStateChanged or adaptiveResults is None: a2d = area.Adaptive2d() a2d.stepOverFactor = 0.01*obj.StepOver a2d.toolDiameter = float(op.tool.Diameter) diff --git a/src/Mod/Path/PathScripts/PathSimulatorGui.py b/src/Mod/Path/PathScripts/PathSimulatorGui.py index 46b95068f502..7f3c3e2f057b 100644 --- a/src/Mod/Path/PathScripts/PathSimulatorGui.py +++ b/src/Mod/Path/PathScripts/PathSimulatorGui.py @@ -486,7 +486,7 @@ def SimStop(self): def InvalidOperation(self): if len(self.activeOps) == 0: return True - if (self.tool == None): + if (self.tool is None): TSError("No tool assigned for the operation") return True return False diff --git a/src/Mod/Robot/RobotExample.py b/src/Mod/Robot/RobotExample.py index d048f21ea0a2..48198d7ad37e 100644 --- a/src/Mod/Robot/RobotExample.py +++ b/src/Mod/Robot/RobotExample.py @@ -57,7 +57,7 @@ # # Working with the robot document objects: # first create a robot in the active document -if(App.activeDocument() == None):App.newDocument() +if(App.activeDocument() is None):App.newDocument() App.activeDocument().addObject("Robot::RobotObject","Robot") # Define the visual representation and the kinematic definition (see [[6-Axis Robot]] for details about that) @@ -105,4 +105,3 @@ for w in App.activeDocument().Trajectory.Trajectory.Waypoints: (A,B,C) = (w.Pos.Rotation.toEuler()) print("LIN {X %.3f,Y %.3f,Z %.3f,A %.3f,B %.3f,C %.3f} ; %s"%(w.Pos.Base.x,w.Pos.Base.y,w.Pos.Base.z,A,B,C,w.Name)) - diff --git a/src/Mod/Sandbox/exportDRAWEXE.py b/src/Mod/Sandbox/exportDRAWEXE.py index 0ad033075d20..d4473438178f 100644 --- a/src/Mod/Sandbox/exportDRAWEXE.py +++ b/src/Mod/Sandbox/exportDRAWEXE.py @@ -513,7 +513,7 @@ def process_object(self,ob,checksupported=False,toplevel=False): curname=nxtname i+=1 elif (isDraftPolygon(ob) and ob.ChamferSize.Value == 0 and\ - ob.FilletRadius.Value == 0 and ob.Support == None) or\ + ob.FilletRadius.Value == 0 and ob.Support is None) or\ ob.TypeId == "Part::Prism" or \ ob.TypeId == "Part::RegularPolygon": if checksupported: return True # The object is supported diff --git a/src/Mod/Sketcher/SketcherExample.py b/src/Mod/Sketcher/SketcherExample.py index da99250cd9d3..f54426696b4f 100644 --- a/src/Mod/Sketcher/SketcherExample.py +++ b/src/Mod/Sketcher/SketcherExample.py @@ -10,7 +10,7 @@ MiddlePoint = 3 # create a document and a Sketch object -if(App.activeDocument() == None):App.newDocument() +if(App.activeDocument() is None):App.newDocument() f = App.activeDocument().addObject("Sketcher::SketchObject","Sketch") @@ -32,5 +32,3 @@ App.activeDocument().recompute() f.Geometry - - diff --git a/src/Mod/Spreadsheet/App/Spreadsheet_legacy.py b/src/Mod/Spreadsheet/App/Spreadsheet_legacy.py index a4db993f2815..1dc9d0672330 100644 --- a/src/Mod/Spreadsheet/App/Spreadsheet_legacy.py +++ b/src/Mod/Spreadsheet/App/Spreadsheet_legacy.py @@ -158,7 +158,7 @@ def parseVariable(self): break value = self.vars.get(var, None) - if value == None: + if value is None: raise ValueError( "Unrecognized variable: '" + var + @@ -233,7 +233,7 @@ def __setattr__(self, key, value): if self.isKey(key): key = key.lower() if DEBUG: print("Setting key ",key," to value ",value) - if (value == "") or (value == None): + if (value == "") or (value is None): # remove cell if key in self._cells.keys(): del self._cells[key] @@ -809,7 +809,7 @@ def update(self): content = getattr(self.spreadsheet.Proxy,cell) if self.spreadsheet.Proxy.isFunction(cell): self.doNotChange = True - if content == None: + if content is None: content = "" if DEBUG: print("Updating ",cell," to ",content) if self.table.item(r,c): @@ -838,7 +838,7 @@ def changeCell(self,r,c,value=None): self.doNotChange = False elif self.spreadsheet: key = "abcdefghijklmnopqrstuvwxyz"[c]+str(r+1) - if value == None: + if value is None: value = self.table.item(r,c).text() if value == "": if DEBUG: print("Wiping "+key) @@ -874,7 +874,7 @@ def setEditLine(self,r,c,orr=None,orc=None): from DraftTools import translate self.label.setText(str(translate("Spreadsheet","Cell"))+" "+c.upper()+str(r)+" :") content = self.spreadsheet.Proxy.getFunction(c+str(r)) - if content == None: + if content is None: content = "" self.lineEdit.setText(str(content)) diff --git a/src/Mod/Spreadsheet/importXLSX.py b/src/Mod/Spreadsheet/importXLSX.py index 4db66a6e1f89..2070b2a0f66b 100644 --- a/src/Mod/Spreadsheet/importXLSX.py +++ b/src/Mod/Spreadsheet/importXLSX.py @@ -226,13 +226,13 @@ def isKey(self, theExpr): if theExpr[0] in sepToken: branch = sepToken[theExpr[0]] - if branch == None: + if branch is None: keyToken = True else: #print('There is a branch. look up: ', theExpr[1]) if (lenExpr > 1) and (theExpr[1] in treeDict[branch]): branch = treeDict[branch][theExpr[0]] - if branch == None: + if branch is None: keyToken = True else: if (lenExpr > 2) and (theExpr[2] in treeDict[branch]): diff --git a/src/Mod/TemplatePyMod/Commands.py b/src/Mod/TemplatePyMod/Commands.py index e87f4a8b854e..4d244cb82bd0 100644 --- a/src/Mod/TemplatePyMod/Commands.py +++ b/src/Mod/TemplatePyMod/Commands.py @@ -69,7 +69,7 @@ def addVertex(self, d): p=PolygonCreator(d,v,10) def IsActive(self): - if FreeCAD.ActiveDocument == None: + if FreeCAD.ActiveDocument is None: return False else: return True @@ -159,7 +159,7 @@ def Activated(self): from pivy import coin global myRenderArea - if myRenderArea == None: + if myRenderArea is None: root = coin.SoSeparator() myCamera = coin.SoPerspectiveCamera() myMaterial = coin.SoMaterial() diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index 4624f9d3ca42..2b381ea67345 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -758,7 +758,7 @@ def testUndo(self): # undo the first transaction self.Doc.undo() - self.failUnless(self.Doc.getObject("test1") == None) + self.failUnless(self.Doc.getObject("test1") is None) self.failUnless(self.Doc.getObject("Del").Integer == 2) self.assertEqual(self.Doc.UndoNames,[]) self.assertEqual(self.Doc.UndoCount,0) @@ -938,7 +938,7 @@ def testGroup(self): self.Doc.openTransaction("Remove") self.Doc.removeObject("Label_2") self.Doc.commitTransaction() - self.failUnless(G1.getObject("Label_2") == None) + self.failUnless(G1.getObject("Label_2") is None) self.Doc.undo() self.failUnless(G1.getObject("Label_2") != None) @@ -954,7 +954,7 @@ def testGroup(self): self.Doc.openTransaction("Remove") self.Doc.removeObject("Label_2") self.Doc.commitTransaction() - self.failUnless(G1.getObject("Label_2") == None) + self.failUnless(G1.getObject("Label_2") is None) self.Doc.openTransaction("Remove") self.Doc.removeObject("Group") self.Doc.commitTransaction() @@ -965,7 +965,7 @@ def testGroup(self): # Remove first object and then the group in one transaction self.Doc.openTransaction("Remove") self.Doc.removeObject("Label_2") - self.failUnless(G1.getObject("Label_2") == None) + self.failUnless(G1.getObject("Label_2") is None) self.Doc.removeObject("Group") self.Doc.commitTransaction() self.Doc.undo() @@ -977,9 +977,9 @@ def testGroup(self): G1.addObject(L3) self.Doc.openTransaction("Remove") self.Doc.removeObject("Label_2") - self.failUnless(G1.getObject("Label_2") == None) + self.failUnless(G1.getObject("Label_2") is None) self.Doc.removeObject("Label_3") - self.failUnless(G1.getObject("Label_3") == None) + self.failUnless(G1.getObject("Label_3") is None) self.Doc.removeObject("Group") self.Doc.commitTransaction() self.Doc.undo() @@ -1001,7 +1001,7 @@ def testGroupAndGeoFeatureGroup(self): grp2 = self.Doc.addObject("App::DocumentObjectGroup","Group2") grp1.addObject(obj1) self.failUnless(obj1.getParentGroup()==grp1) - self.failUnless(obj1.getParentGeoFeatureGroup()==None) + self.failUnless(obj1.getParentGeoFeatureGroup() is None) self.failUnless(grp1.hasObject(obj1)) grp2.addObject(obj1) self.failUnless(grp1.hasObject(obj1)==False) @@ -1012,8 +1012,8 @@ def testGroupAndGeoFeatureGroup(self): prt2 = self.Doc.addObject("App::Part","Part2") prt1.addObject(grp2) - self.failUnless(grp2.getParentGeoFeatureGroup()==prt1) - self.failUnless(grp2.getParentGroup()==None) + self.failUnless(grp2.getParentGeoFeatureGroup() == prt1) + self.failUnless(grp2.getParentGroup() is None) self.failUnless(grp2.hasObject(obj1)) self.failUnless(prt1.hasObject(grp2)) self.failUnless(prt1.hasObject(obj1)) diff --git a/src/Tools/updatefromcrowdin.py b/src/Tools/updatefromcrowdin.py index 368e50bec654..ef2a33460e86 100755 --- a/src/Tools/updatefromcrowdin.py +++ b/src/Tools/updatefromcrowdin.py @@ -128,12 +128,12 @@ def updateqrc(qrcpath,lncode): for i in range(len(resources)): if ".qm" in resources[i]: pos = i - if pos == None: + if pos is None: print("No existing .qm file in this resource. Appending to the end position") for i in range(len(resources)): if "" in resources[i]: pos = i-1 - if pos == None: + if pos is None: print("ERROR: couldn't add qm files to this resource: " + qrcpath) sys.exit() @@ -264,4 +264,3 @@ def doLanguage(lncode,fmodule=""): print("ERROR: language path for " + ln + " not found!") else: doLanguage(ln,fmodule) -