eric6/Debugger/DebugUI.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8265
0090cfa83159
child 8400
b3eefd7e58d1
--- a/eric6/Debugger/DebugUI.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/Debugger/DebugUI.py	Sat May 01 14:27:20 2021 +0200
@@ -9,6 +9,7 @@
 
 import os
 import copy
+import contextlib
 
 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, Qt
 from PyQt5.QtGui import QKeySequence
@@ -70,7 +71,7 @@
         @param debugViewer reference to the debug viewer widget
         @param project reference to the project object
         """
-        super(DebugUI, self).__init__(ui)
+        super().__init__(ui)
         
         self.ui = ui
         self.viewmanager = vm
@@ -169,7 +170,7 @@
         self.passive = Preferences.getDebugger("PassiveDbgEnabled")
     
     def showNotification(self, notification,
-                         kind=NotificationTypes.Information, timeout=None):
+                         kind=NotificationTypes.INFORMATION, timeout=None):
         """
         Public method to show some notification message.
         
@@ -837,10 +838,7 @@
         """
         self.editorOpen = True
         
-        if fn:
-            editor = self.viewmanager.getOpenEditor(fn)
-        else:
-            editor = None
+        editor = self.viewmanager.getOpenEditor(fn) if fn else None
         self.__checkActions(editor)
         
     def __lastEditorClosed(self):
@@ -867,10 +865,7 @@
         
         @param editor editor window
         """
-        if editor:
-            fn = editor.getFileName()
-        else:
-            fn = None
+        fn = editor.getFileName() if editor else None
         
         cap = 0
         if fn:
@@ -1150,10 +1145,10 @@
                     os.path.basename(program), status, info)
             if status != 0:
                 timeout = 0
-                kind = NotificationTypes.Warning
+                kind = NotificationTypes.WARNING
             else:
                 timeout = None
-                kind = NotificationTypes.Information
+                kind = NotificationTypes.INFORMATION
             self.ui.showNotification(
                 UI.PixmapCache.getPixmap("debug48"),
                 self.tr("Program terminated"), msg, kind=kind,
@@ -1241,22 +1236,18 @@
         ):
             res = None
             if stackTrace:
-                try:
+                with contextlib.suppress(UnicodeError, OSError):
                     file, line = stackTrace[0][:2]
                     source, encoding = Utilities.readEncodedFile(file)
                     source = source.splitlines(True)
                     if len(source) >= line:
                         lineFlags = Utilities.extractLineFlags(
                             source[line - 1].strip())
-                        try:
+                        with contextlib.suppress(IndexError):
                             lineFlags += Utilities.extractLineFlags(
                                 source[line].strip(), flagsLine=True)
-                        except IndexError:
-                            pass
                         if "__IGNORE_EXCEPTION__" in lineFlags:
                             res = E5MessageBox.No
-                except (UnicodeError, OSError):
-                    pass
                 if res != E5MessageBox.No:
                     self.viewmanager.setFileLine(
                         stackTrace[0][0], stackTrace[0][1], True)
@@ -1310,9 +1301,11 @@
                 self.ui.setDebugProfile()
                 self.debugActGrp.setEnabled(True)
                 return
-            elif res == E5MessageBox.Ignore:
-                if exceptionType not in self.excIgnoreList:
-                    self.excIgnoreList.append(exceptionType)
+            elif (
+                res == E5MessageBox.Ignore and
+                exceptionType not in self.excIgnoreList
+            ):
+                self.excIgnoreList.append(exceptionType)
         
         if self.lastAction != -1:
             if self.lastAction == 2:
@@ -1633,10 +1626,7 @@
         for row in range(model.rowCount()):
             index = model.index(row, 0)
             filename, line, cond = model.getBreakPointByIndex(index)[:3]
-            if not cond:
-                formattedCond = ""
-            else:
-                formattedCond = " : {0}".format(cond[:20])
+            formattedCond = " : {0}".format(cond[:20]) if cond else ""
             bpSuffix = " : {0:d}{1}".format(line, formattedCond)
             act = self.breakpointsMenu.addAction(
                 "{0}{1}".format(
@@ -1697,10 +1687,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        if runProject:
-            cap = self.tr("Coverage of Project")
-        else:
-            cap = self.tr("Coverage of Script")
+        cap = (
+            self.tr("Coverage of Project")
+            if runProject else
+            self.tr("Coverage of Script")
+        )
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 2,
@@ -1841,10 +1832,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        if runProject:
-            cap = self.tr("Profile of Project")
-        else:
-            cap = self.tr("Profile of Script")
+        cap = (
+            self.tr("Profile of Project")
+            if runProject else
+            self.tr("Profile of Script")
+        )
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 3,
@@ -1985,10 +1977,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        if runProject:
-            cap = self.tr("Run Project")
-        else:
-            cap = self.tr("Run Script")
+        cap = (
+            self.tr("Run Project")
+            if runProject else
+            self.tr("Run Script")
+        )
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 1,
@@ -2125,10 +2118,11 @@
         
         # Get the command line arguments, the working directory and the
         # exception reporting flag.
-        if debugProject:
-            cap = self.tr("Debug Project")
-        else:
-            cap = self.tr("Debug Script")
+        cap = (
+            self.tr("Debug Project")
+            if debugProject else
+            self.tr("Debug Script")
+        )
         dlg = StartDialog(
             cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
             self.envHistory, self.exceptions, self.ui, 0,

eric ide

mercurial