From 35505b451ad27432478cc6779a6316543d61ca67 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sun, 30 Jun 2019 14:32:03 -0700 Subject: [PATCH] Addressed pylint warnings for PathPost --- src/Mod/Path/PathScripts/PathPost.py | 17 ++++++++------- src/Mod/Path/PathScripts/PathPostProcessor.py | 21 +++++++++---------- src/Mod/Path/PathScripts/PostUtils.py | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathPost.py b/src/Mod/Path/PathScripts/PathPost.py index af23559346..f0df65c5cf 100644 --- a/src/Mod/Path/PathScripts/PathPost.py +++ b/src/Mod/Path/PathScripts/PathPost.py @@ -50,15 +50,17 @@ def translate(context, text, disambig=None): class _TempObject: - Path = None - Name = "Fixture" - InList = [] - Label = "Fixture" + # pylint: disable=no-init + Path = None + Name = "Fixture" + InList = [] + Label = "Fixture" class DlgSelectPostProcessor: def __init__(self, parent=None): + # pylint: disable=unused-argument self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgSelectPostProcessor.ui") firstItem = None for post in PathPreferences.allEnabledPostProcessors(): @@ -93,6 +95,7 @@ class DlgSelectPostProcessor: class CommandPathPost: + # pylint: disable=no-init subpart = 1 def resolveFileName(self, job): @@ -188,7 +191,7 @@ class CommandPathPost: return False - def exportObjectsWith(self, objs, job, needFilename=True, filepart=None): + def exportObjectsWith(self, objs, job, needFilename=True): PathLog.track() # check if the user has a project and has set the default post and # output filename @@ -234,7 +237,7 @@ class CommandPathPost: elif hasattr(sel, "Path"): try: job = PathUtils.findParentJob(sel) - except Exception: + except Exception: # pylint: disable=broad-except job = None else: job = None @@ -378,7 +381,7 @@ class CommandPathPost: postlist.append(sublist) fail = True - rc = '' + rc = '' # pylint: disable=unused-variable if split: for slist in postlist: (fail, rc) = self.exportObjectsWith(slist, job) diff --git a/src/Mod/Path/PathScripts/PathPostProcessor.py b/src/Mod/Path/PathScripts/PathPostProcessor.py index c8eb427990..bd1c3530f1 100644 --- a/src/Mod/Path/PathScripts/PathPostProcessor.py +++ b/src/Mod/Path/PathScripts/PathPostProcessor.py @@ -22,7 +22,6 @@ # * * # *************************************************************************** -import FreeCAD import PathScripts.PathLog as PathLog import PathScripts.PathPreferences as PathPreferences import sys @@ -47,7 +46,7 @@ class PostProcessor: namespace = {} #can't modify function local scope with exec in python3 - exec("import %s as current_post" % postname, namespace) + exec("import %s as current_post" % postname, namespace) # pylint: disable=exec-used current_post = namespace['current_post'] # make sure the script is reloaded if it was previously loaded @@ -56,40 +55,34 @@ class PostProcessor: # resulting in 2 load messages if the script outputs one of those. try: # Python 2.7 - exec("reload(%s)" % 'current_post') + exec("reload(%s)" % 'current_post') # pylint: disable=exec-used except NameError: # Python 3.4+ - from importlib import reload - exec("reload(%s)" % 'current_post') + from importlib import reload # pylint: disable=redefined-builtin,unused-variable + exec("reload(%s)" % 'current_post') # pylint: disable=exec-used sys.path = syspath instance = PostProcessor(current_post) - instance.units = None if hasattr(current_post, "UNITS"): if current_post.UNITS == "G21": instance.units = "Metric" else: instance.units = "Inch" - instance.machineName = None if hasattr(current_post, "MACHINE_NAME"): instance.machineName = current_post.MACHINE_NAME - instance.cornerMax = None if hasattr(current_post, "CORNER_MAX"): instance.cornerMax = {'x': current_post.CORNER_MAX['x'], 'y': current_post.CORNER_MAX['y'], 'z': current_post.CORNER_MAX['z']} - instance.cornerMin = None if hasattr(current_post, "CORNER_MIN"): instance.cornerMin = {'x': current_post.CORNER_MIN['x'], 'y': current_post.CORNER_MIN['y'], 'z': current_post.CORNER_MIN['z']} - instance.tooltip = None - instance.tooltipArgs = None if hasattr(current_post, "TOOLTIP"): instance.tooltip = current_post.TOOLTIP if hasattr(current_post, "TOOLTIP_ARGS"): @@ -98,6 +91,12 @@ class PostProcessor: def __init__(self, script): self.script = script + self.tooltip = None + self.tooltipArgs = None + self.cornerMax = None + self.cornerMin = None + self.units = None + self.machineName = None def export(self, obj, filename, args): return self.script.export(obj, filename, args) diff --git a/src/Mod/Path/PathScripts/PostUtils.py b/src/Mod/Path/PathScripts/PostUtils.py index a75a59f8b7..26f6ba491e 100644 --- a/src/Mod/Path/PathScripts/PostUtils.py +++ b/src/Mod/Path/PathScripts/PostUtils.py @@ -52,12 +52,12 @@ class GCodeHighlighter(QtGui.QSyntaxHighlighter): self.highlightingRules.append((QtCore.QRegExp("\\bF[0-9\\.]+\\b"),speedFormat)) def highlightBlock(self, text): - for pattern, format in self.highlightingRules: + for pattern, hlFormat in self.highlightingRules: expression = QtCore.QRegExp(pattern) index = expression.indexIn(text) while index >= 0: length = expression.matchedLength() - self.setFormat(index, length, format) + self.setFormat(index, length, hlFormat) index = expression.indexIn(text, index + length)