Fixed some 'lambda' related issues by converting them to 'functools.partial'.

Sat, 02 Jan 2021 15:18:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Jan 2021 15:18:36 +0100
changeset 7937
181d1160f617
parent 7936
f9f85cf6d102
child 7938
1d3a2a0dac22

Fixed some 'lambda' related issues by converting them to 'functools.partial'.

eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric6/UI/UserInterface.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Feeds/FeedsDialog.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/History/HistoryMenu.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/PersonalInformationManager/PersonalInformationManager.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/Session/SessionManager.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/SiteInfo/SiteInfoDialog.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/TabManager/TabManagerWidget.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/UserAgent/UserAgentMenu.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
eric6/WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
diff -r f9f85cf6d102 -r 181d1160f617 eric6/DebugClients/Python/DebugClientBase.py
--- a/eric6/DebugClients/Python/DebugClientBase.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Sat Jan 02 15:18:36 2021 +0100
@@ -1512,7 +1512,7 @@
         Private method to return the variables of a frame to the debug server.
         
         @param var list encoded name of the requested variable
-        @type list of strings
+        @type list of str
         @param frmnr distance of frame reported on. 0 is the current frame
         @type int
         @param scope 1 to report global variables, 0 for local variables
diff -r f9f85cf6d102 -r 181d1160f617 eric6/UI/UserInterface.py
--- a/eric6/UI/UserInterface.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/UI/UserInterface.py	Sat Jan 02 15:18:36 2021 +0100
@@ -14,6 +14,7 @@
 import json
 import datetime
 import getpass
+import functools
 
 from PyQt5.QtCore import (
     pyqtSlot, QTimer, QFile, QFileInfo, pyqtSignal, PYQT_VERSION_STR, QDate,
@@ -3606,7 +3607,7 @@
                     act.setObjectName("{0}@@{1}".format(toolGroup[0],
                                       tool['menutext']))
                     act.triggered.connect(
-                        lambda: self.__toolActionTriggered(act))
+                        functools.partial(self.__toolActionTriggered, act))
                     self.toolGroupActions[act.objectName()] = act
                     
                     self.toolbarManager.addAction(act, category)
@@ -3647,7 +3648,7 @@
                                   tool['menutext'], self)
                     act.setObjectName(key)
                     act.triggered.connect(
-                        lambda: self.__toolActionTriggered(act))
+                        functools.partial(self.__toolActionTriggered, act))
                     self.toolGroupActions[key] = act
                     
                     self.toolbarManager.addAction(act, category)
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/Feeds/FeedsDialog.py
--- a/eric6/WebBrowser/Feeds/FeedsDialog.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/Feeds/FeedsDialog.py	Sat Jan 02 15:18:36 2021 +0100
@@ -7,6 +7,8 @@
 Module implementing a dialog to add RSS feeds.
 """
 
+import functools
+
 from PyQt5.QtCore import QUrl
 from PyQt5.QtWidgets import QDialog, QPushButton, QLabel
 
@@ -47,7 +49,8 @@
             label.setText(feed[0])
             self.feedsLayout.addWidget(label, row, 0)
             self.feedsLayout.addWidget(button, row, 1)
-            button.clicked.connect(lambda: self.__addFeed(button))
+            button.clicked.connect(
+                functools.partial(self.__addFeed, button))
         
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/History/HistoryMenu.py
--- a/eric6/WebBrowser/History/HistoryMenu.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/History/HistoryMenu.py	Sat Jan 02 15:18:36 2021 +0100
@@ -8,6 +8,7 @@
 """
 
 import sys
+import functools
 
 from PyQt5.QtCore import (
     pyqtSignal, Qt, QMimeData, QUrl, QModelIndex, QSortFilterProxyModel,
@@ -440,7 +441,7 @@
                 title)
             act.setData(index)
             act.triggered.connect(
-                lambda: self.__tabWidget.restoreClosedTab(act))
+                functools.partial(self.__tabWidget.restoreClosedTab, act))
             index += 1
         self.__closedTabsMenu.addSeparator()
         self.__closedTabsMenu.addAction(
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/PersonalInformationManager/PersonalInformationManager.py
--- a/eric6/WebBrowser/PersonalInformationManager/PersonalInformationManager.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/PersonalInformationManager/PersonalInformationManager.py	Sat Jan 02 15:18:36 2021 +0100
@@ -8,6 +8,8 @@
 fields.
 """
 
+import functools
+
 from PyQt5.QtCore import Qt, QObject, QPoint
 from PyQt5.QtWidgets import QDialog, QMenu
 
@@ -153,7 +155,8 @@
             if info:
                 act = submenu.addAction(self.__translations[key])
                 act.setData(info)
-                act.triggered.connect(lambda: self.__insertData(act))
+                act.triggered.connect(
+                    functools.partial(self.__insertData, act))
         
         submenu.addSeparator()
         submenu.addAction(self.tr("Edit Personal Information"),
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/Session/SessionManager.py
--- a/eric6/WebBrowser/Session/SessionManager.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/Session/SessionManager.py	Sat Jan 02 15:18:36 2021 +0100
@@ -9,6 +9,7 @@
 
 import os
 import json
+import functools
 
 from PyQt5.QtCore import (
     pyqtSlot, pyqtSignal, Qt, QObject, QTimer, QDir, QFile, QFileInfo,
@@ -370,7 +371,8 @@
             act.setChecked(session.isActive)
             act.setData(session.filePath)
             actionGroup.addAction(act)
-            act.triggered.connect(lambda: self.__sessionActTriggered(act))
+            act.triggered.connect(
+                functools.partial(self.__sessionActTriggered, act))
     
     @pyqtSlot()
     def __sessionActTriggered(self, act):
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/SiteInfo/SiteInfoDialog.py
--- a/eric6/WebBrowser/SiteInfo/SiteInfoDialog.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/SiteInfo/SiteInfoDialog.py	Sat Jan 02 15:18:36 2021 +0100
@@ -287,16 +287,16 @@
             return
         
         menu = QMenu()
-        act = menu.addAction(self.tr("Copy Image Location to Clipboard"))
-        act.setData(itm.text(1))
-        act.triggered.connect(lambda: self.__copyAction(act))
-        act = menu.addAction(self.tr("Copy Image Name to Clipboard"))
-        act.setData(itm.text(0))
-        act.triggered.connect(lambda: self.__copyAction(act))
+        act1 = menu.addAction(self.tr("Copy Image Location to Clipboard"))
+        act1.setData(itm.text(1))
+        act1.triggered.connect(lambda: self.__copyAction(act1))
+        act2 = menu.addAction(self.tr("Copy Image Name to Clipboard"))
+        act2.setData(itm.text(0))
+        act2.triggered.connect(lambda: self.__copyAction(act2))
         menu.addSeparator()
-        act = menu.addAction(self.tr("Save Image"))
-        act.setData(self.imagesTree.indexOfTopLevelItem(itm))
-        act.triggered.connect(lambda: self.__saveImage(act))
+        act3 = menu.addAction(self.tr("Save Image"))
+        act3.setData(self.imagesTree.indexOfTopLevelItem(itm))
+        act3.triggered.connect(lambda: self.__saveImage(act3))
         menu.exec(self.imagesTree.viewport().mapToGlobal(pos))
     
     def __copyAction(self, act):
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/TabManager/TabManagerWidget.py
--- a/eric6/WebBrowser/TabManager/TabManagerWidget.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/TabManager/TabManagerWidget.py	Sat Jan 02 15:18:36 2021 +0100
@@ -525,16 +525,16 @@
         menu.addSeparator()
         
         if self.__isBrowserSelected():
-            act = menu.addAction(
+            act1 = menu.addAction(
                 UI.PixmapCache.getIcon("bookmark22"),
                 self.tr("&Bookmark checked tabs"))
-            act.setObjectName("bookmarkSelection")
-            act.triggered.connect(lambda: self.__processActions(act))
-            act = menu.addAction(
+            act1.setObjectName("bookmarkSelection")
+            act1.triggered.connect(lambda: self.__processActions(act1))
+            act2 = menu.addAction(
                 UI.PixmapCache.getIcon("tabClose"),
                 self.tr("&Close checked tabs"))
-            act.setObjectName("closeSelection")
-            act.triggered.connect(lambda: self.__processActions(act))
+            act2.setObjectName("closeSelection")
+            act2.triggered.connect(lambda: self.__processActions(act2))
         
         menu.exec(self.__tree.viewport().mapToGlobal(pos))
     
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/UserAgent/UserAgentMenu.py
--- a/eric6/WebBrowser/UserAgent/UserAgentMenu.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/UserAgent/UserAgentMenu.py	Sat Jan 02 15:18:36 2021 +0100
@@ -8,6 +8,7 @@
 """
 
 import os
+import functools
 
 from PyQt5.QtCore import QXmlStreamReader, QFile, QIODevice
 from PyQt5.QtWidgets import (
@@ -160,7 +161,8 @@
                 act.setToolTip(userAgent)
                 act.setCheckable(True)
                 act.setChecked(userAgent == currentUserAgentString)
-                act.triggered.connect(lambda: self.__changeUserAgent(act))
+                act.triggered.connect(
+                    functools.partial(self.__changeUserAgent, act))
                 if menuStack:
                     menuStack[-1].addAction(act)
                 else:
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/WebBrowserView.py
--- a/eric6/WebBrowser/WebBrowserView.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/WebBrowserView.py	Sat Jan 02 15:18:36 2021 +0100
@@ -9,6 +9,7 @@
 """
 
 import os
+import functools
 
 from PyQt5.QtCore import (
     pyqtSignal, pyqtSlot, Qt, QUrl, QFileInfo, QTimer, QEvent, QPoint,
@@ -616,7 +617,7 @@
                 act = menu.addAction(suggestion)
                 act.setFont(boldFont)
                 act.triggered.connect(
-                    lambda: self.__replaceMisspelledWord)(act)
+                    functools.partial(self.__replaceMisspelledWord, act))
             
             if not bool(menu.actions()):
                 menu.addAction(self.tr("No suggestions")).setEnabled(False)
@@ -783,7 +784,7 @@
                 act.setData(engine.getSearchQuery(
                     hitTest.imageUrl(), searchEngineName))
                 act.triggered.connect(
-                    lambda: self.__searchImage(act))
+                    functools.partial(self.__searchImage, act))
         
         menu.addSeparator()
         act = menu.addAction(
@@ -900,29 +901,29 @@
             googleTranslatorUrl = QUrl(
                 "http://translate.google.com/#auto/{0}/{1}".format(
                     langCode, self.selectedText()))
-            act = menu.addAction(
+            act1 = menu.addAction(
                 UI.PixmapCache.getIcon("translate"),
                 self.tr("Google Translate"))
-            act.setData(googleTranslatorUrl)
-            act.triggered.connect(
-                lambda: self.__openLinkInNewTab(act))
+            act1.setData(googleTranslatorUrl)
+            act1.triggered.connect(
+                lambda: self.__openLinkInNewTab(act1))
             wiktionaryUrl = QUrl(
                 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}"
                 .format(langCode, self.selectedText()))
-            act = menu.addAction(
+            act2 = menu.addAction(
                 UI.PixmapCache.getIcon("wikipedia"),
                 self.tr("Dictionary"))
-            act.setData(wiktionaryUrl)
-            act.triggered.connect(
-                lambda: self.__openLinkInNewTab(act))
+            act2.setData(wiktionaryUrl)
+            act2.triggered.connect(
+                lambda: self.__openLinkInNewTab(act2))
             menu.addSeparator()
         
         guessedUrl = QUrl.fromUserInput(self.selectedText().strip())
         if self.__isUrlValid(guessedUrl):
-            act = menu.addAction(self.tr("Go to web address"))
-            act.setData(guessedUrl)
-            act.triggered.connect(
-                lambda: self.__openLinkInNewTab(act))
+            act3 = menu.addAction(self.tr("Go to web address"))
+            act3.setData(guessedUrl)
+            act3.triggered.connect(
+                lambda: self.__openLinkInNewTab(act3))
     
     def __createPageContextMenu(self, menu):
         """
@@ -1004,12 +1005,12 @@
             w3url = QUrl.fromEncoded(
                 b"http://validator.w3.org/check?uri=" +
                 QUrl.toPercentEncoding(bytes(self.url().toEncoded()).decode()))
-            act = menu.addAction(
+            act1 = menu.addAction(
                 UI.PixmapCache.getIcon("w3"),
                 self.tr("Validate Page"))
-            act.setData(w3url)
-            act.triggered.connect(
-                lambda: self.__openLinkInNewTab(act))
+            act1.setData(w3url)
+            act1.triggered.connect(
+                lambda: self.__openLinkInNewTab(act1))
             
             from .WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
             languages = Preferences.toList(
@@ -1025,12 +1026,12 @@
                     b"&u=" +
                     QUrl.toPercentEncoding(
                         bytes(self.url().toEncoded()).decode()))
-                act = menu.addAction(
+                act2 = menu.addAction(
                     UI.PixmapCache.getIcon("translate"),
                     self.tr("Google Translate"))
-                act.setData(googleTranslatorUrl)
-            act.triggered.connect(
-                lambda: self.__openLinkInNewTab(act))
+                act2.setData(googleTranslatorUrl)
+                act2.triggered.connect(
+                    lambda: self.__openLinkInNewTab(act2))
     
     def __checkForForm(self, act, pos):
         """
diff -r f9f85cf6d102 -r 181d1160f617 eric6/WebBrowser/WebBrowserWindow.py
--- a/eric6/WebBrowser/WebBrowserWindow.py	Sat Jan 02 12:15:33 2021 +0100
+++ b/eric6/WebBrowser/WebBrowserWindow.py	Sat Jan 02 15:18:36 2021 +0100
@@ -10,6 +10,7 @@
 import os
 import shutil
 import sys
+import functools
 
 from PyQt5.QtCore import (
     pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, QUrl, QProcess,
@@ -2741,8 +2742,8 @@
             view.page().runJavaScript(
                 script,
                 WebBrowserPage.SafeJsWorld,
-                lambda res: self.__bookmarkAllCallback(folder, urlStr,
-                                                       title, res))
+                functools.partial(self.__bookmarkAllCallback,
+                                  folder, urlStr, title))
     
     def __bookmarkAllCallback(self, folder, url, title, res):
         """

eric ide

mercurial