clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 17 Aug 2017 11:39:10 +0300
changeset 1762 fcc406143e5b
parent 1761 8c98bad90b8d
child 1763 bcc07ff2362c
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
BeremizIDE.py
IDEFrame.py
PLCControler.py
PLCOpenEditor.py
controls/VariablePanel.py
dialogs/ActionBlockDialog.py
dialogs/BrowseLocationsDialog.py
dialogs/DiscoveryDialog.py
dialogs/PouActionDialog.py
dialogs/PouDialog.py
dialogs/PouTransitionDialog.py
dialogs/SearchInProjectDialog.py
editors/CodeFileEditor.py
editors/DataTypeEditor.py
editors/ResourceEditor.py
editors/Viewer.py
plcopen/definitions.py
plcopen/plcopen.py
util/TranslationCatalogs.py
util/Zeroconf.py
xmlclass/xsdschema.py
--- a/BeremizIDE.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/BeremizIDE.py	Thu Aug 17 11:39:10 2017 +0300
@@ -287,9 +287,12 @@
         self._RecursiveAddMenuItems(parent, GetAddMenuItems())
 
     def _init_coll_HelpMenu_Items(self, parent):
-        handler = lambda event: {
-            wx.MessageBox(version.GetCommunityHelpMsg(), _(u'Community support'), wx.OK | wx.ICON_INFORMATION)
-        }
+        def handler(event):
+            return wx.MessageBox(
+                version.GetCommunityHelpMsg(),
+                _(u'Community support'),
+                wx.OK | wx.ICON_INFORMATION)
+
         id = wx.NewId()
         parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
         self.Bind(wx.EVT_MENU, handler, id=id)
--- a/IDEFrame.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/IDEFrame.py	Thu Aug 17 11:39:10 2017 +0300
@@ -2557,7 +2557,8 @@
 #-------------------------------------------------------------------------------
 
 
-UPPER_DIV = lambda x, y: (x / y) + {True: 0, False: 1}[(x % y) == 0]
+def UPPER_DIV(x, y):
+    return (x / y) + {True: 0, False: 1}[(x % y) == 0]
 
 
 class GraphicPrintout(wx.Printout):
--- a/PLCControler.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/PLCControler.py	Thu Aug 17 11:39:10 2017 +0300
@@ -34,7 +34,7 @@
 import util.paths as paths
 from time import localtime
 from collections import OrderedDict, namedtuple
-
+from util.TranslationCatalogs import NoTranslate
 from plcopen import *
 from graphics.GraphicCommons import *
 from PLCGenerator import *
@@ -96,7 +96,7 @@
 
 
 def GetUneditableNames():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("User-defined POUs"), _("Functions"), _("Function Blocks"),
             _("Programs"), _("Data Types"), _("Transitions"), _("Actions"),
             _("Configurations"), _("Resources"), _("Properties")]
@@ -138,8 +138,12 @@
 #-------------------------------------------------------------------------------
 
 
-_StringValue = lambda x: x
-_BoolValue = lambda x: x in ["true", "0"]
+def _StringValue(x):
+    return x
+
+
+def _BoolValue(x):
+    return x in ["true", "0"]
 
 
 def _translate_args(translations, args):
--- a/PLCOpenEditor.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/PLCOpenEditor.py	Thu Aug 17 11:39:10 2017 +0300
@@ -162,9 +162,12 @@
         #AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT,
         #      kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3')
 
-        handler = lambda event: {
-            wx.MessageBox(version.GetCommunityHelpMsg(), _(u'Community support'), wx.OK | wx.ICON_INFORMATION)
-        }
+        def handler(event):
+            return wx.MessageBox(
+                version.GetCommunityHelpMsg(),
+                _(u'Community support'),
+                wx.OK | wx.ICON_INFORMATION)
+
         id = wx.NewId()
         parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
         self.Bind(wx.EVT_MENU, handler, id=id)
--- a/controls/VariablePanel.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/controls/VariablePanel.py	Thu Aug 17 11:39:10 2017 +0300
@@ -38,7 +38,7 @@
 from LocationCellEditor import LocationCellEditor
 from util.BitmapLibrary import GetBitmap
 from PLCControler import _VariableInfos
-
+from util.TranslationCatalogs import NoTranslate
 #-------------------------------------------------------------------------------
 #                                 Helpers
 #-------------------------------------------------------------------------------
@@ -49,14 +49,14 @@
 
 
 def GetVariableTableColnames(location):
-    _ = lambda x: x
+    _ = NoTranslate
     if location:
     	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
     return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
 
 
 def GetOptions(constant=True, retain=True, non_retain=True):
-    _ = lambda x: x
+    _ = NoTranslate
     options = [""]
     if constant:
         options.append(_("Constant"))
@@ -71,7 +71,7 @@
 
 
 def GetFilterChoiceTransfer():
-    _ = lambda x: x
+    _ = NoTranslate
     return {_("All"): _("All"), _("Interface"): _("Interface"),
             _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"),
             _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
--- a/dialogs/ActionBlockDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/ActionBlockDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -29,19 +29,19 @@
 from controls import CustomGrid, CustomTable
 from util.BitmapLibrary import GetBitmap
 from PLCControler import _ActionInfos
-
+from util.TranslationCatalogs import NoTranslate
 #-------------------------------------------------------------------------------
 #                                  Helpers
 #-------------------------------------------------------------------------------
 
 
 def GetActionTableColnames():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("Qualifier"), _("Duration"), _("Type"), _("Value"), _("Indicator")]
 
 
 def GetTypeList():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("Action"), _("Variable"), _("Inline")]
 
 #-------------------------------------------------------------------------------
--- a/dialogs/BrowseLocationsDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/BrowseLocationsDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -30,6 +30,7 @@
 from plcopen.structures import LOCATIONDATATYPES
 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
 from util.BitmapLibrary import GetBitmap
+from util.TranslationCatalogs import NoTranslate
 
 #-------------------------------------------------------------------------------
 #                                   Helpers
@@ -37,7 +38,7 @@
 
 
 def GetDirFilterChoiceOptions():
-    _ = lambda x: x
+    _ = NoTranslate
     return [(_("All"), [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]),
             (_("Input"), [LOCATION_VAR_INPUT]),
             (_("Output"), [LOCATION_VAR_OUTPUT]),
@@ -48,7 +49,7 @@
 
 
 def GetTypeFilterChoiceOptions():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("All"),
             _("Type and derivated"),
             _("Type strict")]
--- a/dialogs/DiscoveryDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/DiscoveryDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -159,9 +159,11 @@
         event.Skip()
 
     def OnIpButton(self, event):
+        def GetColText(col):
+            return self.getColumnText(self.LatestSelection, col)
+
         if self.LatestSelection is not None:
-            addr = lambda col: self.getColumnText(self.LatestSelection, col)
-            self.URI = "%s://%s:%s" % tuple(map(addr, (1, 2, 3)))
+            self.URI = "%s://%s:%s" % tuple(map(GetColText, (1, 2, 3)))
             self.EndModal(wx.ID_OK)
         event.Skip()
 
--- a/dialogs/PouActionDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/PouActionDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -26,10 +26,11 @@
 import wx
 
 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
+from util.TranslationCatalogs import NoTranslate
 
 
 def GetActionLanguages():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("IL"), _("ST"), _("LD"), _("FBD")]
 
 
--- a/dialogs/PouDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/PouDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -26,10 +26,11 @@
 import wx
 
 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
+from util.TranslationCatalogs import NoTranslate
 
 
 def GetPouTypes():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("function"), _("functionBlock"), _("program")]
 
 
@@ -37,7 +38,7 @@
 
 
 def GetPouLanguages():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")]
 
 
--- a/dialogs/PouTransitionDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/PouTransitionDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -26,6 +26,7 @@
 import wx
 
 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
+from util.TranslationCatalogs import NoTranslate
 
 #-------------------------------------------------------------------------------
 #                                POU Transition Dialog
@@ -33,7 +34,7 @@
 
 
 def GetTransitionLanguages():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("IL"), _("ST"), _("LD"), _("FBD")]
 
 
--- a/dialogs/SearchInProjectDialog.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/dialogs/SearchInProjectDialog.py	Thu Aug 17 11:39:10 2017 +0300
@@ -24,8 +24,9 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 import re
+import wx
 from plcopen.plcopen import *
-import wx
+from util.TranslationCatalogs import NoTranslate
 
 #-------------------------------------------------------------------------------
 #                          Search In Project Dialog
@@ -33,7 +34,7 @@
 
 
 def GetElementsChoices():
-    _ = lambda x: x
+    _ = NoTranslate
     return [("datatype", _("Data Type")),
             ("function", _("Function")),
             ("functionBlock", _("Function Block")),
--- a/editors/CodeFileEditor.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/editors/CodeFileEditor.py	Thu Aug 17 11:39:10 2017 +0300
@@ -37,6 +37,7 @@
 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos, NAVIGATION_KEYS
 from controls.VariablePanel import VARIABLE_NAME_SUFFIX_MODEL
 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
+from util.TranslationCatalogs import NoTranslate
 
 [STC_CODE_ERROR, STC_CODE_SEARCH_RESULT,
  STC_CODE_SECTION] = range(15, 18)
@@ -740,7 +741,7 @@
         self.Table.ResetView(self.VariablesGrid)
 
     def GetVariableTableColnames(self):
-        _ = lambda x: x
+        _ = NoTranslate
     	return ["#", _("Name"), _("Type"), _("Initial"), _("Description"), _("OnChange"), _("Options")]
 
     def RefreshModel(self):
--- a/editors/DataTypeEditor.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/editors/DataTypeEditor.py	Thu Aug 17 11:39:10 2017 +0300
@@ -35,6 +35,7 @@
 from dialogs import ArrayTypeDialog
 from EditorPanel import EditorPanel
 from util.BitmapLibrary import GetBitmap
+from util.TranslationCatalogs import NoTranslate
 
 #-------------------------------------------------------------------------------
 #                                    Helpers
@@ -48,12 +49,12 @@
 
 
 def GetElementsTableColnames():
-    _ = lambda x: x
+    _ = NoTranslate
     return ["#", _("Name"), _("Type"), _("Initial Value")]
 
 
 def GetDatatypeTypes():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("Directly"), _("Subrange"), _("Enumerated"), _("Array"), _("Structure")]
 
 
--- a/editors/ResourceEditor.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/editors/ResourceEditor.py	Thu Aug 17 11:39:10 2017 +0300
@@ -32,6 +32,7 @@
 from EditorPanel import EditorPanel
 from util.BitmapLibrary import GetBitmap
 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType
+from util.TranslationCatalogs import NoTranslate
 #-------------------------------------------------------------------------------
 #                          Configuration Editor class
 #-------------------------------------------------------------------------------
@@ -65,18 +66,20 @@
 #-------------------------------------------------------------------------------
 
 def GetTasksTableColnames():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")]
 
 
 def GetTaskTriggeringOptions():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("Interrupt"), _("Cyclic")]
 
 
 TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()])
 
-SingleCellEditor = lambda *x: wx.grid.GridCellChoiceEditor()
+
+def SingleCellEditor(*x):
+    return wx.grid.GridCellChoiceEditor()
 
 
 def CheckSingle(single, varlist):
@@ -84,7 +87,7 @@
 
 
 def GetInstancesTableColnames():
-    _ = lambda x: x
+    _ = NoTranslate
     return [_("Name"), _("Type"), _("Task")]
 
 
--- a/editors/Viewer.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/editors/Viewer.py	Thu Aug 17 11:39:10 2017 +0300
@@ -117,8 +117,13 @@
     return powerRailCreationFunction
 
 
-NEGATED_VALUE = lambda x: x if x is not None else False
-MODIFIER_VALUE = lambda x: x if x is not None else 'none'
+def NEGATED_VALUE(x):
+    return x if x is not None else False
+
+
+def MODIFIER_VALUE(x):
+    return x if x is not None else 'none'
+
 
 CONTACT_TYPES = {(True, "none"): CONTACT_REVERSE,
                  (False, "rising"): CONTACT_RISING,
--- a/plcopen/definitions.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/plcopen/definitions.py	Thu Aug 17 11:39:10 2017 +0300
@@ -26,12 +26,13 @@
 
 from os.path import join, split, realpath
 import util.paths as paths
+from util.TranslationCatalogs import NoTranslate
 sd = paths.AbsDir(__file__)
 
 # Override gettext _ in this module
 # since we just want string to be added to dictionnary
 # but translation should happen here
-_ = lambda x: x
+_ = NoTranslate
 
 LANGUAGES = ["IL", "ST", "FBD", "LD", "SFC"]
 
--- a/plcopen/plcopen.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/plcopen/plcopen.py	Thu Aug 17 11:39:10 2017 +0300
@@ -154,7 +154,11 @@
 
 
 PLCOpenParser = GenerateParserFromXSD(paths.AbsNeighbourFile(__file__, "tc6_xml_v201.xsd"))
-PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP)
+
+
+def PLCOpen_XPath(xpath):
+    return etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP)
+
 
 LOAD_POU_PROJECT_TEMPLATE = """
 <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201"
--- a/util/TranslationCatalogs.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/util/TranslationCatalogs.py	Thu Aug 17 11:39:10 2017 +0300
@@ -52,3 +52,7 @@
         if domain is not None:
             locale.AddCatalogLookupPathPrefix(locale_dir)
             locale.AddCatalog(domain)
+
+
+def NoTranslate(x):
+        return x
--- a/util/Zeroconf.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/util/Zeroconf.py	Thu Aug 17 11:39:10 2017 +0300
@@ -995,14 +995,16 @@
                 if not expired:
                     oldrecord.resetTTL(record)
                 else:
+                    def callback(x):
+                        return self.listener.removeService(x, self.type, record.alias)
                     del(self.services[record.alias.lower()])
-                    callback = lambda x: self.listener.removeService(x, self.type, record.alias)
                     self.list.append(callback)
                     return
             except:
                 if not expired:
+                    def callback(x):
+                        return self.listener.addService(x, self.type, record.alias)
                     self.services[record.alias.lower()] = record
-                    callback = lambda x: self.listener.addService(x, self.type, record.alias)
                     self.list.append(callback)
 
             expires = record.getExpirationTime(75)
--- a/xmlclass/xsdschema.py	Thu Aug 17 10:12:04 2017 +0300
+++ b/xmlclass/xsdschema.py	Thu Aug 17 11:39:10 2017 +0300
@@ -421,7 +421,8 @@
                     return result
             return True
 
-        SimpleTypeInitialValue = lambda: []
+        def SimpleTypeInitialValue():
+            return []
 
         GenerateSimpleType = GenerateSimpleTypeXMLText(lambda x: " ".join(map(itemtypeinfos["generate"], x)))