Modernized some code and corrected some code style issues. eric7

Wed, 22 Nov 2023 17:19:10 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 22 Nov 2023 17:19:10 +0100
branch
eric7
changeset 10331
c1a2ff7e3575
parent 10330
5ea038882dd6
child 10332
7308cfc6e558

Modernized some code and corrected some code style issues.

scripts/compileUiFiles.py file | annotate | diff | comparison | revisions
scripts/install.py file | annotate | diff | comparison | revisions
scripts/uninstall.py file | annotate | diff | comparison | revisions
src/eric7/DebugClients/Python/DebugBase.py file | annotate | diff | comparison | revisions
src/eric7/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
src/eric7/EricNetwork/EricSslCertificateSelectionDialog.py file | annotate | diff | comparison | revisions
src/eric7/EricNetwork/EricSslCertificatesDialog.py file | annotate | diff | comparison | revisions
src/eric7/PipInterface/piplicenses.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginVcsPySvn.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginVcsSubversion.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardDotDesktop.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardEricMessageBox.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardQColorDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardQFileDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardQFontDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardQInputDialog.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/PluginWizardQMessageBox.py file | annotate | diff | comparison | revisions
src/eric7/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py file | annotate | diff | comparison | revisions
src/eric7/Preferences/ConfigurationPages/EditorFilePage.py file | annotate | diff | comparison | revisions
src/eric7/Preferences/ConfigurationPages/EmailPage.py file | annotate | diff | comparison | revisions
src/eric7/Preferences/ConfigurationPages/NetworkPage.py file | annotate | diff | comparison | revisions
src/eric7/Preferences/__init__.py file | annotate | diff | comparison | revisions
src/eric7/QScintilla/Editor.py file | annotate | diff | comparison | revisions
src/eric7/QScintilla/Exporters/ExporterHTML.py file | annotate | diff | comparison | revisions
src/eric7/SystemUtilities/PySideImporter.py file | annotate | diff | comparison | revisions
src/eric7/Testing/Interfaces/PytestRunner.py file | annotate | diff | comparison | revisions
src/eric7/Tools/webBrowserSupport.py file | annotate | diff | comparison | revisions
src/eric7/UI/EmailDialog.py file | annotate | diff | comparison | revisions
src/eric7/UI/Previewers/PreviewerHTML.py file | annotate | diff | comparison | revisions
src/eric7/UI/UserInterface.py file | annotate | diff | comparison | revisions
src/eric7/Utilities/__init__.py file | annotate | diff | comparison | revisions
src/eric7/WebBrowser/Network/NetworkManager.py file | annotate | diff | comparison | revisions
src/eric7/WebBrowser/Tools/WebIconLoader.py file | annotate | diff | comparison | revisions
src/eric7/WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
src/eric7/eric7_browser.py file | annotate | diff | comparison | revisions
--- a/scripts/compileUiFiles.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/scripts/compileUiFiles.py	Wed Nov 22 17:19:10 2023 +0100
@@ -94,7 +94,7 @@
     ProcessPoolExecutor = None
     if workers != 1:
         try:
-            from concurrent.futures import ProcessPoolExecutor  # __IGNORE_WARNING__
+            from concurrent.futures import ProcessPoolExecutor  # noqa: I101, I103
         except NotImplementedError:
             workers = 1
 
--- a/scripts/install.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/scripts/install.py	Wed Nov 22 17:19:10 2023 +0100
@@ -611,14 +611,12 @@
     """
     Clean up the Desktop and Start Menu entries for Windows.
     """
-    global doCleanDesktopLinks, forceCleanDesktopLinks
-
-    try:
-        from pywintypes import com_error  # __IGNORE_WARNING__
-    except ImportError:
+    if importlib.util.find_spec("pywintypes") is None:
         # links were not created by install.py
         return
 
+    global doCleanDesktopLinks, forceCleanDesktopLinks
+
     regPath = (
         "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"
         + "\\User Shell Folders"
@@ -1045,10 +1043,7 @@
     """
     Create Desktop and Start Menu links.
     """
-    try:
-        # check, if pywin32 is available
-        from win32com.client import Dispatch  # __IGNORE_WARNING__
-    except (ImportError, ModuleNotFoundError):  # noqa: M514
+    if importlib.util.find_spec("win32com") is None:
         installed = pipInstall(
             "pywin32",
             "\nThe Python package 'pywin32' could not be imported.",
@@ -1525,9 +1520,10 @@
         print("Yours is {0}.".format(".".join(str(v) for v in sys.version_info[:3])))
         exit(5)
 
-    try:
-        import xml.etree  # __IGNORE_WARNING__
-    except ImportError:
+    if (
+        importlib.util.find_spec("xml") is None
+        or importlib.util.find_spec("xml.etree") is None
+    ):
         print("Your Python installation is missing the XML module.")
         print("Please install it and try again.")
         exit(5)
@@ -1557,25 +1553,17 @@
             exit(1)
     print("Found PyQt6")
 
-    try:
-        pyuic = "pyuic6"
-        from PyQt6 import uic  # __IGNORE_WARNING__
-    except ImportError as err:
+    pyuic = "pyuic6"
+    if importlib.util.find_spec("PyQt6.uic") is None:
         print("Sorry, {0} is not installed.".format(pyuic))
-        if verbose:
-            print("Error: {0}".format(err))
         exit(1)
     print("Found {0}".format(pyuic))
 
-    try:
-        from PyQt6 import QtWebEngineWidgets  # __IGNORE_WARNING__
-    except ImportError as err:
+    if importlib.util.find_spec("PyQt6.QtWebEngineWidgets") is None:
         if isSudo:
             print("Optional 'PyQt6-WebEngine' could not be detected.")
         else:
-            msg = "Optional 'PyQt6-WebEngine' could not be detected.{0}".format(
-                "\nError: {0}".format(err) if verbose else ""
-            )
+            msg = "Optional 'PyQt6-WebEngine' could not be detected."
             pipInstall(
                 "PyQt6-WebEngine>={0}".format(
                     versionToStr(requiredVersions["pyqt6-webengine"])
@@ -1584,15 +1572,11 @@
             )
     print("Found PyQt6-WebEngine")
 
-    try:
-        from PyQt6 import QtCharts  # __IGNORE_WARNING__
-    except ImportError as err:
+    if importlib.util.find_spec("PyQt6.QtCharts") is None:
         if isSudo:
             print("Optional 'PyQt6-Charts' could not be detected.")
         else:
-            msg = "Optional 'PyQt6-Charts' could not be detected.{0}".format(
-                "\nError: {0}".format(err) if verbose else ""
-            )
+            msg = "Optional 'PyQt6-Charts' could not be detected."
             pipInstall(
                 "PyQt6-Charts>={0}".format(
                     versionToStr(requiredVersions["pyqt6-charts"])
@@ -1601,28 +1585,15 @@
             )
     print("Found PyQt6-Charts")
 
-    try:
-        from PyQt6 import Qsci  # __IGNORE_WARNING__
-    except ImportError as err:
-        msg = "'PyQt6-QScintilla' could not be detected.{0}".format(
-            "\nError: {0}".format(err) if verbose else ""
-        )
+    if importlib.util.find_spec("PyQt6.Qsci") is None:
+        msg = "'PyQt6-QScintilla' could not be detected."
         installed = not isSudo and pipInstall(
             "PyQt6-QScintilla>={0}".format(
                 versionToStr(requiredVersions["pyqt6-qscintilla"])
             ),
             msg,
         )
-        if installed:
-            # try to import it again
-            try:
-                from PyQt6 import Qsci  # __IGNORE_WARNING__
-
-                message = None
-            except ImportError as msg:
-                message = str(msg)
-        else:
-            message = "PyQt6-QScintilla could not be installed."
+        message = None if installed else "PyQt6-QScintilla could not be installed."
         if message:
             print("Sorry, please install QScintilla2 and")
             print("its PyQt6 wrapper.")
@@ -1845,7 +1816,9 @@
 
     # print version info for additional modules
     with contextlib.suppress(NameError, AttributeError):
-        print("PyQt6-Charts:", QtCharts.PYQT_CHART_VERSION_STR)
+        from PyQt6.QtCharts import PYQT_CHART_VERSION_STR  # noqa: I101, I102
+
+        print("PyQt6-Charts:", PYQT_CHART_VERSION_STR)
 
     with contextlib.suppress(ImportError, AttributeError):
         from PyQt6 import QtWebEngineCore  # noqa: I101, I102
@@ -1928,7 +1901,7 @@
     ProcessPoolExecutor = None
     if workers != 1:
         try:
-            from concurrent.futures import ProcessPoolExecutor  # __IGNORE_WARNING__
+            from concurrent.futures import ProcessPoolExecutor  # noqa: I101, I103
         except NotImplementedError:
             workers = 1
 
--- a/scripts/uninstall.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/scripts/uninstall.py	Wed Nov 22 17:19:10 2023 +0100
@@ -13,6 +13,7 @@
 import argparse
 import contextlib
 import glob
+import importlib
 import os
 import shutil
 import sys
@@ -237,9 +238,7 @@
     """
     Clean up the Desktop and Start Menu entries for Windows.
     """
-    try:
-        from pywintypes import com_error  # __IGNORE_WARNING__
-    except ImportError:
+    if importlib.util.find_spec("pywintypes") is None:
         # links were not created by install.py
         return
 
--- a/src/eric7/DebugClients/Python/DebugBase.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/DebugClients/Python/DebugBase.py	Wed Nov 22 17:19:10 2023 +0100
@@ -682,7 +682,7 @@
 
             try:
                 lineNumbers = [
-                    l for _, _, l in frame.f_code.co_lines() if l is not None
+                    line for _, _, line in frame.f_code.co_lines() if line is not None
                 ]
             except AttributeError:
                 # backward compatibility code for Python 3.10 and below
@@ -777,7 +777,7 @@
         tb_lineno = None
         if frame is None:
             fr = self.getFrame()
-        elif type(frame) is list:
+        elif isinstance(frame, list):
             fr, tb_lineno = frame.pop(0)
         else:
             fr = frame
@@ -826,7 +826,7 @@
             stack.append([fname, fline, ffunc, fargs])
 
             # is it a stack frame or exception list?
-            if type(frame) is list:
+            if isinstance(frame, list):
                 if frame != []:
                     fr, tb_lineno = frame.pop(0)
                 else:
--- a/src/eric7/DebugClients/Python/DebugClientBase.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/DebugClients/Python/DebugClientBase.py	Wed Nov 22 17:19:10 2023 +0100
@@ -12,6 +12,7 @@
 import codeop
 import contextlib
 import fnmatch
+import importlib
 import json
 import os
 import re
@@ -33,7 +34,7 @@
 
 from AsyncFile import AsyncFile, AsyncPendingWrite
 from BreakpointWatch import Breakpoint, Watch
-from DebugBase import printerr, setRecursionLimit  # __IGNORE_WARNING__
+from DebugBase import printerr, setRecursionLimit
 from DebugConfig import NonExpandableTypes, SpecialAttributes
 from DebugUtilities import formatargvalues, getargvalues, prepareJsonCommand
 from FlexCompleter import Completer
@@ -1030,14 +1031,10 @@
 
         @return client capabilities (integer)
         """
-        try:
-            import PyProfile  # __IGNORE_WARNING__
-
-            with contextlib.suppress(KeyError):
-                del sys.modules["PyProfile"]
+        if importlib.util.find_spec("PyProfile") is None:
+            return self.clientCapabilities & ~DebugClientCapabilities.HasProfiler
+        else:
             return self.clientCapabilities
-        except ImportError:
-            return self.clientCapabilities & ~DebugClientCapabilities.HasProfiler
 
     def readReady(self, stream):
         """
--- a/src/eric7/EricNetwork/EricSslCertificateSelectionDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/EricNetwork/EricSslCertificateSelectionDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -114,7 +114,7 @@
         Private slot to show data of the selected certificate.
         """
         with contextlib.suppress(ImportError):
-            from eric7.EricNetwork.EricSslCertificatesInfoDialog import (  # __IGNORE_WARNING__
+            from eric7.EricNetwork.EricSslCertificatesInfoDialog import (  # noqa: I101
                 EricSslCertificatesInfoDialog,
             )
 
--- a/src/eric7/EricNetwork/EricSslCertificatesDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/EricNetwork/EricSslCertificatesDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -121,7 +121,7 @@
         Private slot to show data of the selected server certificate.
         """
         with contextlib.suppress(ImportError):
-            from eric7.EricNetwork.EricSslCertificatesInfoDialog import (  # __IGNORE_WARNING__
+            from eric7.EricNetwork.EricSslCertificatesInfoDialog import (  # noqa: I101
                 EricSslCertificatesInfoDialog,
             )
 
@@ -340,7 +340,7 @@
         Private slot to show data of the selected CA certificate.
         """
         with contextlib.suppress(ImportError):
-            from eric7.EricNetwork.EricSslCertificatesInfoDialog import (  # __IGNORE_WARNING__
+            from eric7.EricNetwork.EricSslCertificatesInfoDialog import (  # noqa: I101
                 EricSslCertificatesInfoDialog,
             )
 
--- a/src/eric7/PipInterface/piplicenses.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/PipInterface/piplicenses.py	Wed Nov 22 17:19:10 2023 +0100
@@ -428,7 +428,7 @@
     uncommon_items = set()
     set_b_lower = {item.lower() for item in set_b}
     for elem in set_a:
-        if not elem.lower() in set_b_lower:
+        if elem.lower() not in set_b_lower:
             uncommon_items.add(elem)
     return uncommon_items
 
--- a/src/eric7/Plugins/PluginVcsPySvn.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginVcsPySvn.py	Wed Nov 22 17:19:10 2023 +0100
@@ -8,6 +8,7 @@
 """
 
 import contextlib
+import importlib
 import os
 
 from PyQt6.QtCore import QCoreApplication, QObject
@@ -75,7 +76,6 @@
     @return dictionary with indicator as key and a tuple with the vcs name
         (string) and vcs display string (string)
     """
-    ##global pluginTypename
     return {
         ".svn": (__header__["pluginTypename"], displayString()),
         "_svn": (__header__["pluginTypename"], displayString()),
@@ -88,12 +88,10 @@
 
     @return display string (string)
     """
-    try:
-        import pysvn  # __IGNORE_WARNING__
-
+    if importlib.util.find_spec("pysvn") is None:
+        return ""
+    else:
         return QCoreApplication.translate("VcsPySvnPlugin", "Subversion (pysvn)")
-    except ImportError:
-        return ""
 
 
 subversionCfgPluginObject = None
--- a/src/eric7/Plugins/PluginVcsSubversion.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginVcsSubversion.py	Wed Nov 22 17:19:10 2023 +0100
@@ -114,14 +114,13 @@
     @param configDlg reference to the configuration dialog (QDialog)
     @return reference to the configuration page
     """
+    from eric7.Plugins.VcsPlugins.vcsSubversion.ConfigurationPage import SubversionPage
+
     global subversionCfgPluginObject
-    from eric7.Plugins.VcsPlugins.vcsSubversion.ConfigurationPage.SubversionPage import (  # __IGNORE_WARNING__
-        SubversionPage,
-    )
 
     if subversionCfgPluginObject is None:
         subversionCfgPluginObject = VcsSubversionPlugin(None)
-    page = SubversionPage(subversionCfgPluginObject)
+    page = SubversionPage.SubversionPage(subversionCfgPluginObject)
     return page
 
 
--- a/src/eric7/Plugins/PluginWizardDotDesktop.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardDotDesktop.py	Wed Nov 22 17:19:10 2023 +0100
@@ -115,6 +115,8 @@
         """
         Private method to handle the wizards action.
         """
+        from eric7.Plugins.WizardPlugins.DotDesktopWizard import DotDesktopWizardDialog
+
         editor = ericApp().getObject("ViewManager").activeWindow()
 
         if editor is None:
@@ -138,11 +140,7 @@
                     ericApp().getObject("ViewManager").newEditor()
                     editor = ericApp().getObject("ViewManager").activeWindow()
 
-            from eric7.Plugins.WizardPlugins.DotDesktopWizard.DotDesktopWizardDialog import (  # __IGNORE_WARNING__
-                DotDesktopWizardDialog,
-            )
-
-            dlg = DotDesktopWizardDialog(None)
+            dlg = DotDesktopWizardDialog.DotDesktopWizardDialog(None)
             if dlg.exec() == QDialog.DialogCode.Accepted:
                 code = dlg.getCode()
                 if code:
--- a/src/eric7/Plugins/PluginWizardEricMessageBox.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardEricMessageBox.py	Wed Nov 22 17:19:10 2023 +0100
@@ -107,11 +107,11 @@
         @param editor reference to the current editor
         @return the generated code (string)
         """
-        from eric7.Plugins.WizardPlugins.EricMessageBoxWizard.EricMessageBoxWizardDialog import (  # __IGNORE_WARNING__
+        from eric7.Plugins.WizardPlugins.EricMessageBoxWizard import (
             EricMessageBoxWizardDialog,
         )
 
-        dlg = EricMessageBoxWizardDialog(None)
+        dlg = EricMessageBoxWizardDialog.EricMessageBoxWizardDialog(None)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             line, index = editor.getCursorPosition()
             indLevel = editor.indentation(line) // editor.indentationWidth()
--- a/src/eric7/Plugins/PluginWizardQColorDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardQColorDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -107,11 +107,11 @@
         @param editor reference to the current editor
         @return the generated code (string) and a success flag (boolean)
         """
-        from eric7.Plugins.WizardPlugins.ColorDialogWizard.ColorDialogWizardDialog import (  # __IGNORE_WARNING__
+        from eric7.Plugins.WizardPlugins.ColorDialogWizard import (
             ColorDialogWizardDialog,
         )
 
-        dlg = ColorDialogWizardDialog(None)
+        dlg = ColorDialogWizardDialog.ColorDialogWizardDialog(None)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             line, index = editor.getCursorPosition()
             indLevel = editor.indentation(line) // editor.indentationWidth()
--- a/src/eric7/Plugins/PluginWizardQFileDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardQFileDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -141,11 +141,9 @@
         @type int
         @return the generated code (string)
         """
-        from eric7.Plugins.WizardPlugins.FileDialogWizard.FileDialogWizardDialog import (  # __IGNORE_WARNING__
-            FileDialogWizardDialog,
-        )
+        from eric7.Plugins.WizardPlugins.FileDialogWizard import FileDialogWizardDialog
 
-        dlg = FileDialogWizardDialog(variant, None)
+        dlg = FileDialogWizardDialog.FileDialogWizardDialog(variant, None)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             line, index = editor.getCursorPosition()
             indLevel = editor.indentation(line) // editor.indentationWidth()
--- a/src/eric7/Plugins/PluginWizardQFontDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardQFontDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -107,11 +107,9 @@
         @param editor reference to the current editor
         @return the generated code (string)
         """
-        from eric7.Plugins.WizardPlugins.FontDialogWizard.FontDialogWizardDialog import (  # __IGNORE_WARNING__
-            FontDialogWizardDialog,
-        )
+        from eric7.Plugins.WizardPlugins.FontDialogWizard import FontDialogWizardDialog
 
-        dlg = FontDialogWizardDialog(None)
+        dlg = FontDialogWizardDialog.FontDialogWizardDialog(None)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             line, index = editor.getCursorPosition()
             indLevel = editor.indentation(line) // editor.indentationWidth()
--- a/src/eric7/Plugins/PluginWizardQInputDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardQInputDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -107,11 +107,11 @@
         @param editor reference to the current editor
         @return the generated code (string)
         """
-        from eric7.Plugins.WizardPlugins.InputDialogWizard.InputDialogWizardDialog import (  # __IGNORE_WARNING__
+        from eric7.Plugins.WizardPlugins.InputDialogWizard import (
             InputDialogWizardDialog,
         )
 
-        dlg = InputDialogWizardDialog(None)
+        dlg = InputDialogWizardDialog.InputDialogWizardDialog(None)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             line, index = editor.getCursorPosition()
             indLevel = editor.indentation(line) // editor.indentationWidth()
--- a/src/eric7/Plugins/PluginWizardQMessageBox.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/PluginWizardQMessageBox.py	Wed Nov 22 17:19:10 2023 +0100
@@ -107,11 +107,9 @@
         @param editor reference to the current editor
         @return the generated code (string)
         """
-        from eric7.Plugins.WizardPlugins.MessageBoxWizard.MessageBoxWizardDialog import (  # __IGNORE_WARNING__
-            MessageBoxWizardDialog,
-        )
+        from eric7.Plugins.WizardPlugins.MessageBoxWizard import MessageBoxWizardDialog
 
-        dlg = MessageBoxWizardDialog(None)
+        dlg = MessageBoxWizardDialog.MessageBoxWizardDialog(None)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             line, index = editor.getCursorPosition()
             indLevel = editor.indentation(line) // editor.indentationWidth()
--- a/src/eric7/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Plugins/WizardPlugins/QRegularExpressionWizard/QRegularExpressionWizardServer.py	Wed Nov 22 17:19:10 2023 +0100
@@ -7,6 +7,7 @@
 Module implementing the PyQt6 server part of the QRegularExpression wizzard.
 """
 
+import importlib
 import json
 import sys
 
@@ -115,12 +116,7 @@
                 if command == "exit":
                     break
                 elif command == "available":
-                    try:
-                        import PyQt6  # __IGNORE_WARNING__
-
-                        responseDict["available"] = True
-                    except ImportError:
-                        responseDict["available"] = False
+                    responseDict["available"] = bool(importlib.util.find_spec("PyQt6"))
                 elif command == "validate":
                     valid, error, errorOffset = rxValidate(
                         commandDict["regexp"], commandDict["options"]
--- a/src/eric7/Preferences/ConfigurationPages/EditorFilePage.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Preferences/ConfigurationPages/EditorFilePage.py	Wed Nov 22 17:19:10 2023 +0100
@@ -7,7 +7,7 @@
 Module implementing the Editor File Handling configuration page.
 """
 
-import sys
+import importlib
 
 from PyQt6.Qsci import QsciScintilla
 from PyQt6.QtCore import pyqtSlot
@@ -402,13 +402,9 @@
         """
         Public slot to perform some polishing actions.
         """
-        try:
-            import pymdownx  # __IGNORE_WARNING__
-
-            self.previewMarkdownPyMdownInstallPushButton.setEnabled(False)
-            del sys.modules["pymdownx"]
-        except ImportError:
-            self.previewMarkdownPyMdownInstallPushButton.setEnabled(True)
+        self.previewMarkdownPyMdownInstallPushButton.setEnabled(
+            bool(importlib.util.find_spec("pymdownx"))
+        )
 
 
 def create(dlg):  # noqa: U100
--- a/src/eric7/Preferences/ConfigurationPages/EmailPage.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Preferences/ConfigurationPages/EmailPage.py	Wed Nov 22 17:19:10 2023 +0100
@@ -271,7 +271,7 @@
 
         try:
             from eric7.EricNetwork import EricGoogleMail  # __IGNORE_WARNING__
-            from eric7.EricNetwork.EricGoogleMailHelpers import (  # __IGNORE_WARNING__
+            from eric7.EricNetwork.EricGoogleMailHelpers import (  # noqa: I101
                 isClientSecretFileAvailable,
             )
 
--- a/src/eric7/Preferences/ConfigurationPages/NetworkPage.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Preferences/ConfigurationPages/NetworkPage.py	Wed Nov 22 17:19:10 2023 +0100
@@ -150,7 +150,7 @@
             "RequestDownloadFilename", self.requestFilenameCheckBox.isChecked()
         )
         if self.__webEngine:
-            from eric7.WebBrowser.Download.DownloadManager import (  # __IGNORE_WARNING__
+            from eric7.WebBrowser.Download.DownloadManager import (  # noqa: I101
                 DownloadManager,
             )
 
--- a/src/eric7/Preferences/__init__.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Preferences/__init__.py	Wed Nov 22 17:19:10 2023 +0100
@@ -2016,7 +2016,7 @@
             try:
                 virtualenvManager = ericApp().getObject("VirtualEnvManager")
             except KeyError:
-                from eric7.VirtualEnv.VirtualenvManager import (  # __IGNORE_WARNING__
+                from eric7.VirtualEnv.VirtualenvManager import (  # noqa: I101
                     VirtualenvManager,
                 )
 
--- a/src/eric7/QScintilla/Editor.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/QScintilla/Editor.py	Wed Nov 22 17:19:10 2023 +0100
@@ -9380,6 +9380,8 @@
             was started (line and index)
         @type tuple of (int, int)
         """
+        from .DocstringGenerator.BaseDocstringGenerator import DocstringMenuForEnterOnly
+
         cursorPosition = self.getCursorPosition()
         if lastCursorPosition != cursorPosition:
             return
@@ -9389,10 +9391,6 @@
 
         generator = self.getDocstringGenerator()
         if generator.hasFunctionDefinition(cursorPosition):
-            from .DocstringGenerator.BaseDocstringGenerator import (  # __IGNORE_WARNING__
-                DocstringMenuForEnterOnly,
-            )
-
             docstringMenu = DocstringMenuForEnterOnly(self)
             act = docstringMenu.addAction(
                 EricPixmapCache.getIcon("fileText"),
--- a/src/eric7/QScintilla/Exporters/ExporterHTML.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/QScintilla/Exporters/ExporterHTML.py	Wed Nov 22 17:19:10 2023 +0100
@@ -10,7 +10,7 @@
 # This code is a port of the C++ code found in SciTE 1.74
 # Original code: Copyright 1998-2006 by Neil Hodgson <neilh@scintilla.org>
 
-import contextlib
+import importlib
 import io
 import os
 import sys
@@ -578,26 +578,24 @@
             extensions.append("nl2br")
 
         pyMdown = False
-        if Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions"):
-            with contextlib.suppress(ImportError):
-                import pymdownx  # __IGNORE_EXCEPTION__ __IGNORE_WARNING__
-
-                # PyPI package is 'pymdown-extensions'
-
-                extensions.extend(
-                    [
-                        "toc",
-                        "pymdownx.extra",
-                        "pymdownx.caret",
-                        "pymdownx.emoji",
-                        "pymdownx.mark",
-                        "pymdownx.tilde",
-                        "pymdownx.keys",
-                        "pymdownx.tasklist",
-                        "pymdownx.smartsymbols",
-                    ]
-                )
-                pyMdown = True
+        if Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions") and bool(
+            importlib.util.find_spec("pymdownx")
+        ):
+            # PyPI package is 'pymdown-extensions'
+            extensions.extend(
+                [
+                    "toc",
+                    "pymdownx.extra",
+                    "pymdownx.caret",
+                    "pymdownx.emoji",
+                    "pymdownx.mark",
+                    "pymdownx.tilde",
+                    "pymdownx.keys",
+                    "pymdownx.tasklist",
+                    "pymdownx.smartsymbols",
+                ]
+            )
+            pyMdown = True
 
         if not pyMdown:
             extensions.extend(["extra", "toc"])
--- a/src/eric7/SystemUtilities/PySideImporter.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/SystemUtilities/PySideImporter.py	Wed Nov 22 17:19:10 2023 +0100
@@ -7,6 +7,7 @@
 Module to check for the presence of PySide2/PySide6 by importing it.
 """
 
+import importlib
 import sys
 
 if __name__ == "__main__":
@@ -19,20 +20,10 @@
         ret = 1
 
     elif pySideVariant == "2":
-        try:
-            import PySide2  # __IGNORE_EXCEPTION__ __IGNORE_WARNING__
-
-            ret = 0
-        except ImportError:
-            ret = 1
+        ret = 1 if importlib.util.find_spec("PySide") is None else 0
 
     elif pySideVariant == "6":
-        try:
-            import PySide6  # __IGNORE_EXCEPTION__ __IGNORE_WARNING__
-
-            ret = 0
-        except ImportError:
-            ret = 1
+        ret = 1 if importlib.util.find_spec("PySide6") is None else 0
 
     else:
         ret = 1
--- a/src/eric7/Testing/Interfaces/PytestRunner.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Testing/Interfaces/PytestRunner.py	Wed Nov 22 17:19:10 2023 +0100
@@ -8,6 +8,7 @@
 """
 
 import contextlib
+import importlib
 import json
 import os
 import sys
@@ -345,11 +346,9 @@
 if __name__ == "__main__":
     command = sys.argv[1]
     if command == "installed":
-        try:
-            import pytest  # __IGNORE_WARNING__
-
+        if bool(importlib.util.find_spec("pytest")):
             sys.exit(0)
-        except ImportError:
+        else:
             sys.exit(1)
 
     elif command == "versions":
--- a/src/eric7/Tools/webBrowserSupport.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Tools/webBrowserSupport.py	Wed Nov 22 17:19:10 2023 +0100
@@ -11,16 +11,17 @@
 it is absent.
 """
 
-import contextlib
+import importlib
 import sys
 
-variant = "None"
-
-with contextlib.suppress(ImportError):
-    from PyQt6 import QtWebEngineWidgets  # __IGNORE_WARNING__
-
-    variant = "QtWebEngine"
-
-print(variant)  # __IGNORE_WARNING_M801__
+variant = (
+    "QtWebEngine"
+    if (
+        bool(importlib.util.find_spec("PyQt6"))
+        and bool(importlib.util.find_spec("PyQt6.QtWebEngineWidgets"))
+    )
+    else "None"
+)
+print(variant)  # noqa: M801
 
 sys.exit(0)
--- a/src/eric7/UI/EmailDialog.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/UI/EmailDialog.py	Wed Nov 22 17:19:10 2023 +0100
@@ -158,7 +158,7 @@
         """
         if self.__helpDialog is None:
             try:
-                from eric7.EricNetwork.EricGoogleMail import (  # __IGNORE_WARNING__
+                from eric7.EricNetwork.EricGoogleMail import (  # noqa: I101
                     GoogleMailHelp,
                 )
 
--- a/src/eric7/UI/Previewers/PreviewerHTML.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/UI/Previewers/PreviewerHTML.py	Wed Nov 22 17:19:10 2023 +0100
@@ -7,7 +7,7 @@
 Module implementing a previewer widget for HTML, Markdown and ReST files.
 """
 
-import contextlib
+import importlib
 import io
 import os
 import re
@@ -778,26 +778,23 @@
             extensions.append("nl2br")
 
         pyMdown = False
-        if usePyMdownExtensions:
-            with contextlib.suppress(ImportError):
-                import pymdownx  # __IGNORE_EXCEPTION__ __IGNORE_WARNING__
-
-                # PyPI package is 'pymdown-extensions'
+        if usePyMdownExtensions and bool(importlib.util.find_spec("pymdownx")):
+            # PyPI package is 'pymdown-extensions'
 
-                extensions.extend(
-                    [
-                        "toc",
-                        "pymdownx.extra",
-                        "pymdownx.caret",
-                        "pymdownx.emoji",
-                        "pymdownx.mark",
-                        "pymdownx.tilde",
-                        "pymdownx.keys",
-                        "pymdownx.tasklist",
-                        "pymdownx.smartsymbols",
-                    ]
-                )
-                pyMdown = True
+            extensions.extend(
+                [
+                    "toc",
+                    "pymdownx.extra",
+                    "pymdownx.caret",
+                    "pymdownx.emoji",
+                    "pymdownx.mark",
+                    "pymdownx.tilde",
+                    "pymdownx.keys",
+                    "pymdownx.tasklist",
+                    "pymdownx.smartsymbols",
+                ]
+            )
+            pyMdown = True
 
         if not pyMdown:
             extensions.extend(["extra", "toc"])
--- a/src/eric7/UI/UserInterface.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/UI/UserInterface.py	Wed Nov 22 17:19:10 2023 +0100
@@ -353,7 +353,7 @@
         )
 
         with contextlib.suppress(ImportError, AttributeError):
-            from eric7.EricWidgets.EricSpellCheckedTextEdit import (  # __IGNORE_WARNING__
+            from eric7.EricWidgets.EricSpellCheckedTextEdit import (  # noqa: I101
                 SpellCheckMixin,
             )
 
@@ -826,9 +826,7 @@
         if Preferences.getUI("ShowTemplateViewer"):
             # Create the template viewer part of the user interface
             logging.debug("Creating Template Viewer...")
-            from eric7.Templates.TemplateViewer import (  # __IGNORE_WARNING_I101__
-                TemplateViewer,
-            )
+            from eric7.Templates.TemplateViewer import TemplateViewer  # noqa: I101
 
             self.templateViewer = TemplateViewer(None, self.viewmanager)
         else:
@@ -838,7 +836,7 @@
         if Preferences.getUI("ShowFileBrowser"):
             # Create the file browser
             logging.debug("Creating File Browser...")
-            from .Browser import Browser  # __IGNORE_WARNING_I101__
+            from .Browser import Browser  # noqa: I101
 
             self.browser = Browser()
         else:
@@ -848,7 +846,7 @@
         if Preferences.getUI("ShowSymbolsViewer"):
             # Create the symbols viewer
             logging.debug("Creating Symbols Viewer...")
-            from .SymbolsWidget import SymbolsWidget  # __IGNORE_WARNING_I101__
+            from .SymbolsWidget import SymbolsWidget  # noqa: I101
 
             self.symbolsViewer = SymbolsWidget()
         else:
@@ -858,9 +856,7 @@
         if Preferences.getUI("ShowCodeDocumentationViewer"):
             # Create the code documentation viewer
             logging.debug("Creating Code Documentation Viewer...")
-            from .CodeDocumentationViewer import (  # __IGNORE_WARNING_I101__
-                CodeDocumentationViewer,
-            )
+            from .CodeDocumentationViewer import CodeDocumentationViewer  # noqa: I101
 
             self.codeDocumentationViewer = CodeDocumentationViewer(self)
         else:
@@ -870,7 +866,7 @@
         if Preferences.getUI("ShowPyPIPackageManager"):
             # Create the PyPI package manager
             logging.debug("Creating PyPI Package Manager...")
-            from eric7.PipInterface.PipPackagesWidget import (  # __IGNORE_WARNING__
+            from eric7.PipInterface.PipPackagesWidget import (  # noqa: I101
                 PipPackagesWidget,
             )
 
@@ -882,7 +878,7 @@
         if Preferences.getUI("ShowCondaPackageManager"):
             # Create the conda package manager
             logging.debug("Creating Conda Package Manager...")
-            from eric7.CondaInterface.CondaPackagesWidget import (  # __IGNORE_WARNING__
+            from eric7.CondaInterface.CondaPackagesWidget import (  # noqa: I101
                 CondaPackagesWidget,
             )
 
@@ -894,9 +890,7 @@
         if Preferences.getUI("ShowCooperation"):
             # Create the chat part of the user interface
             logging.debug("Creating Chat Widget...")
-            from eric7.Cooperation.ChatWidget import (  # __IGNORE_WARNING_I101__
-                ChatWidget,
-            )
+            from eric7.Cooperation.ChatWidget import ChatWidget  # noqa: I101
 
             self.cooperation = ChatWidget(self)
         else:
@@ -906,7 +900,7 @@
         if Preferences.getUI("ShowIrc"):
             # Create the IRC part of the user interface
             logging.debug("Creating IRC Widget...")
-            from eric7.Network.IRC.IrcWidget import IrcWidget  # __IGNORE_WARNING_I101__
+            from eric7.Network.IRC.IrcWidget import IrcWidget  # noqa: I101
 
             self.irc = IrcWidget(self)
         else:
@@ -916,7 +910,7 @@
         if Preferences.getUI("ShowMicroPython"):
             # Create the MicroPython part of the user interface
             logging.debug("Creating MicroPython Widget...")
-            from eric7.MicroPython.MicroPythonWidget import (  # __IGNORE_WARNING_I101__
+            from eric7.MicroPython.MicroPythonWidget import (  # noqa: I101
                 MicroPythonWidget,
             )
 
@@ -928,7 +922,7 @@
         if Preferences.getUI("ShowNumbersViewer"):
             # Create the numbers viewer
             logging.debug("Creating Numbers Viewer...")
-            from .NumbersWidget import NumbersWidget  # __IGNORE_WARNING_I101__
+            from .NumbersWidget import NumbersWidget  # noqa: I101
 
             self.numbersViewer = NumbersWidget()
         else:
@@ -956,7 +950,7 @@
         self.__replaceFileDialog = None
         if Preferences.getUI("ShowFindFileWidget"):
             # Create the find in files widget
-            from .FindFileWidget import FindFileWidget  # __IGNORE_WARNING_I101__
+            from .FindFileWidget import FindFileWidget  # noqa: I101
 
             self.__findFileWidget = FindFileWidget(self.project, self)
             self.__findFileWidget.sourceFile.connect(self.viewmanager.openSourceFile)
@@ -972,9 +966,7 @@
         self.__findLocationDialog = None
         if Preferences.getUI("ShowFindLocationWidget"):
             # Create the find location (file) widget
-            from .FindLocationWidget import (  # __IGNORE_WARNING_I101__
-                FindLocationWidget,
-            )
+            from .FindLocationWidget import FindLocationWidget  # noqa: I101
 
             self.__findLocationWidget = FindLocationWidget(self.project, self)
             self.__findLocationWidget.sourceFile.connect(
@@ -998,9 +990,7 @@
         ):
             # Create the embedded help viewer
             logging.debug("Creating Internal Help Viewer...")
-            from eric7.HelpViewer.HelpViewerWidget import (  # __IGNORE_WARNING_I101__
-                HelpViewerWidget,
-            )
+            from eric7.HelpViewer.HelpViewerWidget import HelpViewerWidget  # noqa: I101
 
             self.__helpViewerWidget = HelpViewerWidget(self)
         else:
@@ -7183,7 +7173,7 @@
         )
 
         with contextlib.suppress(ImportError, AttributeError):
-            from eric7.EricWidgets.EricSpellCheckedTextEdit import (  # __IGNORE_WARNING__
+            from eric7.EricWidgets.EricSpellCheckedTextEdit import (  # noqa: I101
                 SpellCheckMixin,
             )
 
@@ -7233,7 +7223,7 @@
         Preferences.convertPasswords(oldPassword, newPassword)
         variant = Globals.getWebBrowserSupport()
         if variant == "QtWebEngine":
-            from eric7.WebBrowser.Passwords.PasswordManager import (  # __IGNORE_WARNING__
+            from eric7.WebBrowser.Passwords.PasswordManager import (  # noqa: I101
                 PasswordManager,
             )
 
--- a/src/eric7/Utilities/__init__.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/Utilities/__init__.py	Wed Nov 22 17:19:10 2023 +0100
@@ -10,6 +10,7 @@
 import codecs
 import contextlib
 import glob
+import importlib
 import json
 import os
 import re
@@ -1055,13 +1056,13 @@
     info.append("  Qt {0}".format(qVersion()))
     info.append("  PyQt6 {0}".format(PYQT_VERSION_STR))
     try:
-        from PyQt6 import QtCharts  # __IGNORE_WARNING_I10__
+        from PyQt6 import QtCharts  # noqa: I101, I102
 
         info.append("  PyQt6-Charts {0}".format(QtCharts.PYQT_CHART_VERSION_STR))
     except (AttributeError, ImportError):
         info.append("  PyQt6-Charts not installed")
     try:
-        from PyQt6 import QtWebEngineCore  # __IGNORE_WARNING_I10__
+        from PyQt6 import QtWebEngineCore  # noqa: I101, I102
 
         info.append(
             "  PyQt6-WebEngine {0}".format(QtWebEngineCore.PYQT_WEBENGINE_VERSION_STR)
@@ -1070,10 +1071,8 @@
         info.append("  PyQt6-WebEngine not installed")
     info.append("  PyQt6-QScintilla {0}".format(QSCINTILLA_VERSION_STR))
     info.append("  sip {0}".format(sip_version_str))
-    with contextlib.suppress(ImportError):
-        from PyQt6 import QtWebEngineWidgets  # __IGNORE_WARNING__
-
-        from eric7.WebBrowser.Tools import WebBrowserTools  # __IGNORE_WARNING_I101__
+    if bool(importlib.util.find_spec("PyQt6.QtWebEngineWidgets")):
+        from eric7.WebBrowser.Tools import WebBrowserTools  # noqa: I101
 
         (
             chromiumVersion,
--- a/src/eric7/WebBrowser/Network/NetworkManager.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/WebBrowser/Network/NetworkManager.py	Wed Nov 22 17:19:10 2023 +0100
@@ -94,7 +94,7 @@
         )
 
         if engine:
-            from eric7.QtHelpInterface.QtHelpSchemeHandler import (  # __IGNORE_WARNING__
+            from eric7.QtHelpInterface.QtHelpSchemeHandler import (  # noqa: I101
                 QtHelpSchemeHandler,
             )
 
--- a/src/eric7/WebBrowser/Tools/WebIconLoader.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/WebBrowser/Tools/WebIconLoader.py	Wed Nov 22 17:19:10 2023 +0100
@@ -9,7 +9,7 @@
 
 from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot
 from PyQt6.QtGui import QIcon, QImage, QPixmap
-from PyQt6.QtNetwork import QNetworkRequest, QSslConfiguration
+from PyQt6.QtNetwork import QNetworkRequest
 
 try:
     from PyQt6.QtNetwork import QSslConfiguration  # __IGNORE_WARNING__
--- a/src/eric7/WebBrowser/WebBrowserWindow.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/WebBrowser/WebBrowserWindow.py	Wed Nov 22 17:19:10 2023 +0100
@@ -3964,7 +3964,7 @@
         Private slot to manage the QtHelp documentation database.
         """
         if WebBrowserWindow._useQtHelp:
-            from eric7.QtHelpInterface.QtHelpDocumentationConfigurationDialog import (  # __IGNORE_WARNING__
+            from eric7.QtHelpInterface.QtHelpDocumentationConfigurationDialog import (  # noqa: I101
                 QtHelpDocumentationConfigurationDialog,
             )
 
@@ -4062,7 +4062,7 @@
         help database.
         """
         if WebBrowserWindow._useQtHelp:
-            from eric7.QtHelpInterface.HelpDocsInstaller import (  # __IGNORE_WARNING__
+            from eric7.QtHelpInterface.HelpDocsInstaller import (  # noqa: I101
                 HelpDocsInstaller,
             )
 
--- a/src/eric7/eric7_browser.py	Tue Nov 21 11:42:45 2023 +0100
+++ b/src/eric7/eric7_browser.py	Wed Nov 22 17:19:10 2023 +0100
@@ -45,7 +45,7 @@
         from PyQt6.QtCore import QTimer
         from PyQt6.QtWidgets import QApplication
 
-        from eric7.EricWidgets import EricMessageBox  # __IGNORE_WARNING__
+        from eric7.EricWidgets import EricMessageBox
 
         app = QApplication([])
         QTimer.singleShot(

eric ide

mercurial