fix pylint error "(undefined-variable) Undefined variable 'X'"
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 16 Oct 2017 17:20:31 +0300
changeset 1872 866fb3ab8778
parent 1871 933fbe9a5e2c
child 1873 e69d7e5aff00
fix pylint error "(undefined-variable) Undefined variable 'X'"
.pylint
Beremiz.py
Beremiz_service.py
CodeFileTreeNode.py
PLCControler.py
PLCOpenEditor.py
connectors/WAMP/__init__.py
dialogs/PouNameDialog.py
dialogs/SFCStepNameDialog.py
docutil/docsvg.py
editors/CodeFileEditor.py
editors/SFCViewer.py
graphics/FBD_Objects.py
graphics/GraphicCommons.py
graphics/LD_Objects.py
graphics/SFC_Objects.py
plcopen/plcopen.py
svgui/pyjs/jsonrpc/web2py/jsonrpc.py
svgui/pyjs/lib/pyjslib.py
svgui/svgui_server.py
svgui/svguilib.py
tests/tools/check_source.sh
xmlclass/xmlclass.py
xmlclass/xsdschema.py
--- a/.pylint	Fri Oct 13 13:17:42 2017 +0300
+++ b/.pylint	Mon Oct 16 17:20:31 2017 +0300
@@ -110,7 +110,7 @@
 
 # List of additional names supposed to be defined in builtins. Remember that
 # you should avoid to define new builtins when possible.
-additional-builtins=_
+additional-builtins=_,website,JS
 
 # List of strings which can identify a callback function by name. A callback
 # name must start or end with one of those strings.
--- a/Beremiz.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/Beremiz.py	Mon Oct 16 17:20:31 2017 +0300
@@ -28,6 +28,10 @@
 import sys
 import getopt
 import time
+
+import wx
+from wx.lib.agw.advancedsplash import AdvancedSplash
+
 import util.paths as paths
 
 
@@ -47,7 +51,6 @@
         return os.path.join(self.app_dir, *args)
 
     def ShowSplashScreen(self):
-        from wx.lib.agw.advancedsplash import AdvancedSplash
         bmp = wx.Image(self.splashPath).ConvertToBitmap()
         self.splash = AdvancedSplash(None, bitmap=bmp)
 
@@ -111,9 +114,6 @@
     def CreateApplication(self):
         BMZ_DBG = os.path.exists("BEREMIZ_DEBUG")
 
-        global wx
-        import wx
-
         if wx.VERSION >= (3, 0, 0):
             self.app = wx.App(redirect=BMZ_DBG)
         else:
@@ -177,6 +177,7 @@
         util.ExceptionHandler.AddExceptHook(version.app_version)
 
     def ShowUI(self):
+        import BeremizIDE
         self.frame = BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath)
         if self.splash:
             self.splash.Close()
--- a/Beremiz_service.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/Beremiz_service.py	Mon Oct 16 17:20:31 2017 +0300
@@ -563,7 +563,7 @@
 if havetwisted:
     if webport is not None:
         try:
-            import runtime.NevowServer as NS  # pylint: disable=C0412
+            import runtime.NevowServer as NS  # pylint: disable=ungrouped-imports
         except Exception, e:
             print(_("Nevow/Athena import failed :"), e)
             webport = None
@@ -571,7 +571,7 @@
 
     if wampconf is not None:
         try:
-            import runtime.WampClient as WC  # pylint: disable=C0412
+            import runtime.WampClient as WC  # pylint: disable=ungrouped-imports
         except Exception, e:
             print(_("WAMP import failed :"), e)
             wampconf = None
--- a/CodeFileTreeNode.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/CodeFileTreeNode.py	Mon Oct 16 17:20:31 2017 +0300
@@ -103,7 +103,6 @@
         self.CodeFileVariables = etree.XPath("variables/variable")
 
         filepath = self.CodeFileName()
-
         if os.path.isfile(filepath):
             xmlfile = open(filepath, 'r')
             codefile_xml = xmlfile.read()
@@ -124,9 +123,10 @@
                     self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
                 self.CreateCodeFileBuffer(True)
             except Exception, exc:
-                msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=CTNName, a2=unicode(exc))
+                msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=self.CTNName(), a2=unicode(exc))
                 self.GetCTRoot().logger.write_error(msg)
                 self.GetCTRoot().logger.write_error(traceback.format_exc())
+                raise Exception
         else:
             self.CodeFile = self.CodeFileParser.CreateRoot()
             self.CreateCodeFileBuffer(False)
--- a/PLCControler.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/PLCControler.py	Mon Oct 16 17:20:31 2017 +0300
@@ -240,7 +240,7 @@
             setattr(self, attr, value if value is not None else "")
 
     def copy(self):
-        return _VariableTreeItem(*[getattr(self, attr) for attr in self.__slots__])
+        return _VariablesTreeItemInfos(*[getattr(self, attr) for attr in self.__slots__])
 
 
 class VariablesTreeInfosFactory(object):
@@ -1592,7 +1592,7 @@
                  "list": [
                     datatype.getname()
                     for datatype in confnodetypes["types"].getdataTypes()
-                    if not only_locatables or self.IsLocatableDataType(datatype, debug)]}
+                    if not only_locatables or self.IsLocatableDataType(datatype)]}
                 for confnodetypes in self.ConfNodeTypes]
 
     def GetVariableLocationTree(self):
--- a/PLCOpenEditor.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/PLCOpenEditor.py	Mon Oct 16 17:20:31 2017 +0300
@@ -35,6 +35,7 @@
 import util.paths as paths
 import util.ExceptionHandler
 from util.misc import InstallLocalRessources
+from docutil.docpdf import open_pdf
 from IDEFrame import IDEFrame, AppendMenu
 from IDEFrame import \
     TITLE, \
--- a/connectors/WAMP/__init__.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/connectors/WAMP/__init__.py	Mon Oct 16 17:20:31 2017 +0300
@@ -138,7 +138,7 @@
                 _WampConnection = threads.blockingCallFromThread(
                     reactor, RegisterWampClient)
             if not _WampSessionEvent.wait(5):
-                _WampConnection = stopConnecting()
+                _WampConnection.stopConnecting()
                 raise Exception(_("WAMP connection timeout"))
 
         def __del__(self):
--- a/dialogs/PouNameDialog.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/dialogs/PouNameDialog.py	Mon Oct 16 17:20:31 2017 +0300
@@ -23,6 +23,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 import wx
+from plcopen.structures import TestIdentifier, IEC_KEYWORDS
 
 # -------------------------------------------------------------------------------
 #                                POU Name Dialog
--- a/dialogs/SFCStepNameDialog.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/dialogs/SFCStepNameDialog.py	Mon Oct 16 17:20:31 2017 +0300
@@ -23,6 +23,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 import wx
+from plcopen.structures import TestIdentifier, IEC_KEYWORDS
 
 # -------------------------------------------------------------------------------
 #                          Edit Step Name Dialog
--- a/docutil/docsvg.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/docutil/docsvg.py	Mon Oct 16 17:20:31 2017 +0300
@@ -33,7 +33,7 @@
     try:
         svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
                                         'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
-    except WindowsError:
+    except OSError:
         svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
                                         'Software\\Classes\\inkscape.svg\\shell\\open\\command')
     svgexepath = svgexepath.replace('"%1"', '')
--- a/editors/CodeFileEditor.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/editors/CodeFileEditor.py	Mon Oct 16 17:20:31 2017 +0300
@@ -393,17 +393,17 @@
 
     def OnMarginClick(self, event):
         # fold and unfold as needed
-        if evt.GetMargin() == 2:
-            if evt.GetShift() and evt.GetControl():
+        if event.GetMargin() == 2:
+            if event.GetShift() and event.GetControl():
                 self.FoldAll()
             else:
-                lineClicked = self.LineFromPosition(evt.GetPosition())
+                lineClicked = self.LineFromPosition(event.GetPosition())
 
                 if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
-                    if evt.GetShift():
+                    if event.GetShift():
                         self.SetFoldExpanded(lineClicked, True)
                         self.Expand(lineClicked, True, True, 1)
-                    elif evt.GetControl():
+                    elif event.GetControl():
                         if self.GetFoldExpanded(lineClicked):
                             self.SetFoldExpanded(lineClicked, False)
                             self.Expand(lineClicked, False, True, 0)
--- a/editors/SFCViewer.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/editors/SFCViewer.py	Mon Oct 16 17:20:31 2017 +0300
@@ -284,12 +284,18 @@
                 self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
                 self.SelectedElement.Refresh()
             wx.CallAfter(self.SetCurrentCursor, 0)
-        elif self.Mode == MODE_WIRE and self.SelectedElement:
-            self.SelectedElement.ResetPoints()
-            self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
-            self.SelectedElement.GeneratePoints()
-            self.SelectedElement.RefreshModel()
-            self.SelectedElement.SetSelected(True)
+        #
+        # FIXME:
+        # This code was forgotten by commit
+        # 9c74d00ce93e from plcopeneditor_history repository
+        # 'Last bugs on block and wire moving, resizing with cursor fixed'
+        #
+        # elif self.Mode == MODE_WIRE and self.SelectedElement:
+        #     self.SelectedElement.ResetPoints()
+        #     self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
+        #     self.SelectedElement.GeneratePoints()
+        #     self.SelectedElement.RefreshModel()
+        #     self.SelectedElement.SetSelected(True)
         event.Skip()
 
     def OnViewerRightUp(self, event):
@@ -328,11 +334,17 @@
                 if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group):
                     self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
                     self.SelectedElement.Refresh()
-            elif self.Mode == MODE_WIRE and self.SelectedElement:
-                self.SelectedElement.ResetPoints()
-                self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
-                self.SelectedElement.GeneratePoints()
-                self.SelectedElement.Refresh()
+            #
+            # FIXME:
+            # This code was forgotten by commit
+            # 9c74d00ce93e from plcopeneditor_history repository
+            # 'Last bugs on block and wire moving, resizing with cursor fixed'
+            #
+            # elif self.Mode == MODE_WIRE and self.SelectedElement:
+            #     self.SelectedElement.ResetPoints()
+            #     self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
+            #     self.SelectedElement.GeneratePoints()
+            #     self.SelectedElement.Refresh()
             self.UpdateScrollPos(event)
         event.Skip()
 
--- a/graphics/FBD_Objects.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/graphics/FBD_Objects.py	Mon Oct 16 17:20:31 2017 +0300
@@ -201,7 +201,7 @@
 
     def SetOutputValues(self, values):
         for output in self.Outputs:
-            output.SetValue(values.get(ouput.getName(), None))
+            output.SetValue(values.get(output.getName(), None))
 
     def GetConnectionResultType(self, connector, connectortype):
         if not TestConnectorName(connector.GetName(), self.Type):
--- a/graphics/GraphicCommons.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/graphics/GraphicCommons.py	Mon Oct 16 17:20:31 2017 +0300
@@ -225,7 +225,7 @@
     return False
 
 
-def ClearHighlight(highlights, highlight_type=None):
+def ClearHighlights(highlights, highlight_type=None):
     if highlight_type is not None:
         return [highlight for highlight in highlights if highlight[2] != highlight_type]
     return []
--- a/graphics/LD_Objects.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/graphics/LD_Objects.py	Mon Oct 16 17:20:31 2017 +0300
@@ -621,7 +621,7 @@
         else:
             highlight_items = self.Highlights.items()
             for name, highlights in highlight_items:
-                highlights = ClearHighlights(highlight, highlight_type)
+                highlights = ClearHighlights(highlights, highlight_type)
                 if len(highlights) == 0:
                     self.Highlights.pop(name)
 
@@ -943,7 +943,7 @@
         else:
             highlight_items = self.Highlights.items()
             for name, highlights in highlight_items:
-                highlights = ClearHighlights(highlight, highlight_type)
+                highlights = ClearHighlights(highlights, highlight_type)
                 if len(highlights) == 0:
                     self.Highlights.pop(name)
 
--- a/graphics/SFC_Objects.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/graphics/SFC_Objects.py	Mon Oct 16 17:20:31 2017 +0300
@@ -972,7 +972,7 @@
         else:
             highlight_items = self.Highlights.items()
             for name, highlights in highlight_items:
-                highlights = ClearHighlights(highlight, highlight_type)
+                highlights = ClearHighlights(highlights, highlight_type)
                 if len(highlights) == 0:
                     self.Highlights.pop(name)
 
--- a/plcopen/plcopen.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/plcopen/plcopen.py	Mon Oct 16 17:20:31 2017 +0300
@@ -2831,7 +2831,7 @@
         elif opened == closed:
             i += 1
         else:
-            raise ValueError(_("\"%s\" is an invalid value!") % value)
+            raise ValueError(_("\"%s\" is an invalid value!") % values)
     return items
 
 
--- a/svgui/pyjs/jsonrpc/web2py/jsonrpc.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/svgui/pyjs/jsonrpc/web2py/jsonrpc.py	Mon Oct 16 17:20:31 2017 +0300
@@ -1,3 +1,6 @@
+# pylint: disable=undefined-variable
+
+
 from svgui.pyjs.jsonrpc.jsonrpc import JSONRPCServiceBase
 
 
--- a/svgui/pyjs/lib/pyjslib.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/svgui/pyjs/lib/pyjslib.py	Mon Oct 16 17:20:31 2017 +0300
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# pylint: disable=too-many-function-args
+# pylint: disable=too-many-function-args,undefined-variable
 
 # iteration from Bob Ippolito's Iteration in JavaScript
 
--- a/svgui/svgui_server.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/svgui/svgui_server.py	Mon Oct 16 17:20:31 2017 +0300
@@ -26,6 +26,7 @@
 
 from nevow import tags, loaders
 import simplejson as json
+import runtime.NevowServer as NS
 
 svgfile = '%(svgfile)s'
 
@@ -113,7 +114,7 @@
     jsClass = u"LiveSVGPage.LiveSVGWidget"
 
     docFactory = loaders.stan(tags.div(render=tags.directive('liveElement'))[
-                                         tags.xml(loaders.xmlfile(os.path.join(WorkingDir, svgfile))),
+                                         tags.xml(loaders.xmlfile(os.path.join(NS.WorkingDir, svgfile))),
                                          ])
 
     def HMIinitialisation(self):
--- a/svgui/svguilib.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/svgui/svguilib.py	Mon Oct 16 17:20:31 2017 +0300
@@ -23,7 +23,9 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
-# pylint: disable=C1001
+# pylint: disable=old-style-class,undefined-variable
+
+
 class button:
 
     def __init__(self, parent, id, args):
--- a/tests/tools/check_source.sh	Fri Oct 13 13:17:42 2017 +0300
+++ b/tests/tools/check_source.sh	Mon Oct 16 17:20:31 2017 +0300
@@ -220,7 +220,8 @@
     disable=$disable,R0914        # (too-many-locals) Too many local variables (18/15)
     disable=$disable,R0915        # (too-many-statements) Too many statements (57/50)
     disable=$disable,R0916        # (too-many-boolean-expressions) Too many boolean expressions in if statement (6/5)
-    
+    disable=$disable,R0101        # (too-many-nested-blocks) Too many nested blocks (7/5)
+
     enable=
     enable=$enable,E1601          # print statement used
     enable=$enable,C0325          # (superfluous-parens) Unnecessary parens after keyword    
@@ -256,6 +257,7 @@
     enable=$enable,E0213          # (no-self-argument) Method should have "self" as first argument
     enable=$enable,E0401          # (import-error) Unable to import 'X'
     enable=$enable,E1121          # (too-many-function-args) Too many positional arguments for function call
+    enable=$enable,E0602          # (undefined-variable) Undefined variable 'X'
     # enable=
 
     options=
--- a/xmlclass/xmlclass.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/xmlclass/xmlclass.py	Mon Oct 16 17:20:31 2017 +0300
@@ -83,12 +83,12 @@
 
     def SetOffset(self, offset):
         if offset == "Z":
-            self.__offset = timedelta(minutes=0)
+            self.__offset = datetime.timedelta(minutes=0)
             self.__name = "UTC"
         else:
             sign = {"-": -1, "+": 1}[offset[0]]
             hours, minutes = [int(val) for val in offset[1:].split(":")]
-            self.__offset = timedelta(minutes=sign * (hours * 60 + minutes))
+            self.__offset = datetime.timedelta(minutes=sign * (hours * 60 + minutes))
             self.__name = ""
 
     def utcoffset(self, dt):
@@ -98,7 +98,7 @@
         return self.__name
 
     def dst(self, dt):
-        return ZERO
+        return datetime.timedelta(0)
 
 
 [
@@ -600,7 +600,7 @@
         "extract": ExtractTag,
         "generate": GenerateTag,
         "initial": lambda: None,
-        "check": lambda x: x is None or infos["minOccurs"] == 0 and value
+        "check": lambda x: x is None or infos["minOccurs"] == 0 and x
     }
 
 
@@ -634,15 +634,15 @@
 
 def GetContentInfos(name, choices):
     for choice_infos in choices:
-        if choices_infos["type"] == "sequence":
-            for element_infos in choices_infos["elements"]:
+        if choice_infos["type"] == "sequence":
+            for element_infos in choice_infos["elements"]:
                 if element_infos["type"] == CHOICE:
                     if GetContentInfos(name, element_infos["choices"]):
-                        return choices_infos
+                        return choice_infos
                 elif element_infos["name"] == name:
-                    return choices_infos
+                    return choice_infos
         elif choice_infos["name"] == name:
-            return choices_infos
+            return choice_infos
     return None
 
 
@@ -743,7 +743,7 @@
                     namespace, childname = DecomposeQualifiedName(child.nodeName)
                     infos = factory.GetQualifiedNameInfos(childname, namespace)
                     if infos["type"] != SYNTAXELEMENT:
-                        raise ValueError("\"%s\" can't be a member child!" % name)
+                        raise ValueError("\"%s\" can't be a member child!" % childname)
                     if element_name in infos["extract"]:
                         children.append(infos["extract"][element_name](factory, child))
                     else:
@@ -849,7 +849,7 @@
                         elements = group["choices"]
                     for element in elements:
                         if element["name"] == parts[1]:
-                            return part[1], part[0]
+                            return parts[1], parts[0]
             if not canbenone:
                 raise ValueError("Unknown element \"%s\" for any defined namespaces!" % name)
         elif namespace in self.Namespaces:
--- a/xmlclass/xsdschema.py	Fri Oct 13 13:17:42 2017 +0300
+++ b/xmlclass/xsdschema.py	Mon Oct 16 17:20:31 2017 +0300
@@ -376,7 +376,7 @@
                     elif facetname == "length":
                         return " "*facetvalue
                     elif facetname == "minLength":
-                        return " "*minLength
+                        return " "*facetvalue
                     elif facetname == "minInclusive" and facetvalue > 0:
                         return facetvalue
                     elif facetname == "minExclusive" and facetvalue >= 0:
@@ -567,7 +567,7 @@
                 content["name"] = "content"
                 extension["elements"].append(content)
             elif group["type"] == "group":
-                elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
+                elmtgroup = factory.FindSchemaElement(group["ref"], ELEMENTSGROUP)
                 if "elements" in elmtgroup:
                     extension["elements"] = elmtgroup["elements"]
                     extension["order"] = elmtgroup["order"]
@@ -650,7 +650,7 @@
                 content["name"] = "content"
                 complexType["elements"].append(content)
             elif group["type"] == "group":
-                elmtgroup = factory.FindSchemaElement(child["ref"], ELEMENTSGROUP)
+                elmtgroup = factory.FindSchemaElement(group["ref"], ELEMENTSGROUP)
                 if "elements" in elmtgroup:
                     complexType["elements"] = elmtgroup["elements"]
                     complexType["order"] = elmtgroup["order"]
@@ -758,7 +758,7 @@
             element["maxOccurs"] = attributes["maxOccurs"]
             return element
         else:
-            raise ValueError("\"%s\" base type isn't defined or circular referenced!" % name)
+            raise ValueError("\"%s\" base type isn't defined or circular referenced!" % attributes["ref"])
 
     elif "name" in attributes:
         element = {"type": ELEMENT, "elmt_type": attributes.get("type", None), "constraints": constraints, "doc": annotations}