eric6/Debugger/DebuggerInterfacePython.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8257
28146736bbfc
--- a/eric6/Debugger/DebuggerInterfacePython.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/Debugger/DebuggerInterfacePython.py	Sat May 01 14:27:20 2021 +0200
@@ -11,6 +11,7 @@
 import os
 import logging
 import shlex
+import contextlib
 
 from PyQt5.QtCore import (
     QObject, QProcess, QProcessEnvironment, QTimer
@@ -44,7 +45,7 @@
         @param passive flag indicating passive connection mode
         @type bool
         """
-        super(DebuggerInterfacePython, self).__init__()
+        super().__init__()
         
         self.__isNetworked = True
         self.__autoContinue = False
@@ -208,10 +209,11 @@
                                            "DebugClients", "Python",
                                            "DebugClient.py")
         
-        if configOverride and configOverride["enable"]:
-            redirect = str(configOverride["redirect"])
-        else:
-            redirect = str(Preferences.getDebugger("Python3Redirect"))
+        redirect = (
+            str(configOverride["redirect"])
+            if configOverride and configOverride["enable"] else
+            str(Preferences.getDebugger("Python3Redirect"))
+        )
         noencoding = (Preferences.getDebugger("Python3NoEncoding") and
                       '--no-encoding' or '')
         multiprocessEnabled = (
@@ -278,11 +280,9 @@
         envlist = shlex.split(
             Preferences.getDebugger("DebugEnvironment"))
         for el in envlist:
-            try:
+            with contextlib.suppress(ValueError):
                 key, value = el.split('=', 1)
                 clientEnv[str(key)] = str(value)
-            except ValueError:
-                pass
         if execPath:
             if "PATH" in clientEnv:
                 clientEnv["PATH"] = os.pathsep.join(
@@ -367,14 +367,14 @@
         debugClient = project.getDebugProperty("DEBUGCLIENT")
         if not venvName:
             venvName = project.getDebugProperty("VIRTUALENV")
-        if not venvName:
-            if project.getProjectLanguage() == "Python3":
-                venvName = Preferences.getDebugger("Python3VirtualEnv")
+        if not venvName and project.getProjectLanguage() == "Python3":
+            venvName = Preferences.getDebugger("Python3VirtualEnv")
         
-        if configOverride and configOverride["enable"]:
-            redirect = str(configOverride["redirect"])
-        else:
-            redirect = str(project.getDebugProperty("REDIRECT"))
+        redirect = (
+            str(configOverride["redirect"])
+            if configOverride and configOverride["enable"] else
+            str(project.getDebugProperty("REDIRECT"))
+        )
         noencoding = (
             '--no-encoding' if project.getDebugProperty("NOENCODING") else ''
         )
@@ -462,11 +462,9 @@
         envlist = shlex.split(
             project.getDebugProperty("ENVIRONMENTSTRING"))
         for el in envlist:
-            try:
+            with contextlib.suppress(ValueError):
                 key, value = el.split('=', 1)
                 clientEnv[str(key)] = str(value)
-            except ValueError:
-                pass
         if execPath:
             if "PATH" in clientEnv:
                 clientEnv["PATH"] = os.pathsep.join(
@@ -602,12 +600,10 @@
         
         if not self.__connections:
             # no active connections anymore
-            try:
+            with contextlib.suppress(RuntimeError):
                 self.debugServer.signalLastClientExited()
-            except RuntimeError:
                 # debug server object might have been deleted already
                 # ignore this
-                pass
             self.__autoContinued.clear()
             self.debugServer.startClient()
     
@@ -915,10 +911,8 @@
         @param temp flag indicating a temporary breakpoint
         @type bool
         """
-        if debuggerId:
-            debuggerList = [debuggerId]
-        else:
-            debuggerList = list(self.__connections.keys())
+        debuggerList = ([debuggerId] if debuggerId
+                        else list(self.__connections.keys()))
         for debuggerId in debuggerList:
             self.__sendJsonCommand("RequestBreakpoint", {
                 "filename": self.translate(fn, False),
@@ -941,10 +935,8 @@
         @param enable flag indicating enabling or disabling a breakpoint
         @type bool
         """
-        if debuggerId:
-            debuggerList = [debuggerId]
-        else:
-            debuggerList = list(self.__connections.keys())
+        debuggerList = ([debuggerId] if debuggerId
+                        else list(self.__connections.keys()))
         for debuggerId in debuggerList:
             self.__sendJsonCommand("RequestBreakpointEnable", {
                 "filename": self.translate(fn, False),
@@ -965,10 +957,8 @@
         @param count number of occurrences to ignore
         @type int
         """
-        if debuggerId:
-            debuggerList = [debuggerId]
-        else:
-            debuggerList = list(self.__connections.keys())
+        debuggerList = ([debuggerId] if debuggerId
+                        else list(self.__connections.keys()))
         for debuggerId in debuggerList:
             self.__sendJsonCommand("RequestBreakpointIgnore", {
                 "filename": self.translate(fn, False),
@@ -989,10 +979,8 @@
         @param temp flag indicating a temporary watch expression
         @type bool
         """
-        if debuggerId:
-            debuggerList = [debuggerId]
-        else:
-            debuggerList = list(self.__connections.keys())
+        debuggerList = ([debuggerId] if debuggerId
+                        else list(self.__connections.keys()))
         for debuggerId in debuggerList:
             # cond is combination of cond and special (s. watch expression
             # viewer)
@@ -1013,10 +1001,8 @@
         @param enable flag indicating enabling or disabling a watch expression
         @type bool
         """
-        if debuggerId:
-            debuggerList = [debuggerId]
-        else:
-            debuggerList = list(self.__connections.keys())
+        debuggerList = ([debuggerId] if debuggerId
+                        else list(self.__connections.keys()))
         for debuggerId in debuggerList:
             # cond is combination of cond and special (s. watch expression
             # viewer)
@@ -1037,10 +1023,8 @@
         @param count number of occurrences to ignore
         @type int
         """
-        if debuggerId:
-            debuggerList = [debuggerId]
-        else:
-            debuggerList = list(self.__connections.keys())
+        debuggerList = ([debuggerId] if debuggerId
+                        else list(self.__connections.keys()))
         for debuggerId in debuggerList:
             # cond is combination of cond and special (s. watch expression
             # viewer)

eric ide

mercurial