diff -r fb0ef164f536 -r 698ae46f40a4 eric6/DebugClients/Python/DebugClientBase.py --- a/eric6/DebugClients/Python/DebugClientBase.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/DebugClients/Python/DebugClientBase.py Sat May 01 14:27:20 2021 +0200 @@ -22,7 +22,7 @@ import types import importlib.util import fnmatch - +import contextlib import DebugClientCapabilities import DebugVariables @@ -54,8 +54,8 @@ """ if DebugClientInstance is None or not DebugClientInstance.redirect: return DebugClientOrigInput(prompt) - - return DebugClientInstance.input(prompt) + else: + return DebugClientInstance.input(prompt) # Use our own input(). try: @@ -77,8 +77,8 @@ """ if DebugClientInstance is None: DebugClientOrigClose(fd) - - DebugClientInstance.close(fd) + else: + DebugClientInstance.close(fd) # use our own close(). if 'close' in dir(os): @@ -107,7 +107,7 @@ ############################################################################### -class DebugClientBase(object): +class DebugClientBase: """ Class implementing the client side of the debugger. @@ -239,10 +239,8 @@ @param terminate flag indicating to terminate (boolean) """ - try: + with contextlib.suppress(Exception): self.set_quit() - except Exception: # secok - pass self.debugging = False self.multiprocessSupport = False @@ -1146,10 +1144,8 @@ """ try: import PyProfile # __IGNORE_WARNING__ - try: + with contextlib.suppress(KeyError): del sys.modules['PyProfile'] - except KeyError: - pass return self.clientCapabilities except ImportError: return ( @@ -1526,10 +1522,8 @@ else: varDict = f.f_locals - if scope == -1: - varlist = [] - else: - varlist = self.__formatVariablesList(varDict, scope, filterList) + varlist = [] if scope == -1 else self.__formatVariablesList( + varDict, scope, filterList) self.sendJsonCommand("ResponseVariables", { "scope": scope, @@ -1761,18 +1755,14 @@ elif qttype == 'QDomAttr': varlist.append(("name", "str", "{0}".format(value.name()))) varlist.append(("value", "str", "{0}".format(value.value()))) - elif qttype == 'QDomCharacterData': - varlist.append(("data", "str", "{0}".format(value.data()))) - elif qttype == 'QDomComment': + elif qttype in ('QDomCharacterData', 'QDomComment', 'QDomText'): varlist.append(("data", "str", "{0}".format(value.data()))) elif qttype == 'QDomDocument': varlist.append(("text", "str", "{0}".format(value.toString()))) elif qttype == 'QDomElement': varlist.append(("tagName", "str", "{0}".format(value.tagName()))) varlist.append(("text", "str", "{0}".format(value.text()))) - elif qttype == 'QDomText': - varlist.append(("data", "str", "{0}".format(value.data()))) - + # Networking stuff elif qttype == 'QHostAddress': varlist.append( @@ -1814,10 +1804,11 @@ filterList = [] if filterList is None else filterList[:] varlist = [] - if scope: - patternFilterObjects = self.globalsFilterObjects - else: - patternFilterObjects = self.localsFilterObjects + patternFilterObjects = ( + self.globalsFilterObjects + if scope else + self.localsFilterObjects + ) if type(dict_) == dict: dict_ = dict_.items() @@ -1846,13 +1837,10 @@ if valtype in filterList: continue elif ( - key in SpecialAttributes and - "special_attributes" in filterList - ): - continue - elif ( - key == "__hash__" and - "builtin_function_or_method" in filterList + (key in SpecialAttributes and + "special_attributes" in filterList) or + (key == "__hash__" and + "builtin_function_or_method" in filterList) ): continue else: @@ -1872,28 +1860,20 @@ # valtypename, e.g. QPoint valtypename = type(value).__name__ - if valtype in filterList: - continue - elif ( - valtype in ("sip.enumtype", "sip.wrappertype") and - 'class' in filterList - ): - continue - elif ( - valtype in ( + if ( + valtype in filterList or + (valtype in ("sip.enumtype", "sip.wrappertype") and + 'class' in filterList) or + (valtype in ( "sip.methoddescriptor", "method_descriptor") and - 'method' in filterList + 'method' in filterList) or + (valtype in ("numpy.ndarray", "array.array") and + 'list' in filterList) or + (valtypename == "MultiValueDict" and + 'dict' in filterList) or + 'instance' in filterList ): continue - elif ( - valtype in ("numpy.ndarray", "array.array") and - 'list' in filterList - ): - continue - elif valtypename == "MultiValueDict" and 'dict' in filterList: - continue - elif 'instance' in filterList: - continue isQt = valtype.startswith(ConfigQtNames) @@ -1961,12 +1941,10 @@ pos -= 1 # Get local and global completions - try: + with contextlib.suppress(AttributeError): localdict = self.currentThread.getFrameLocals(self.framenr) localCompleter = Completer(localdict).complete self.__getCompletionList(text, localCompleter, completions) - except AttributeError: - pass cf = self.currentThread.getCurrentFrame() frmnr = self.framenr @@ -1974,10 +1952,7 @@ cf = cf.f_back frmnr -= 1 - if cf is None: - globaldict = self.debugMod.__dict__ - else: - globaldict = cf.f_globals + globaldict = self.debugMod.__dict__ if cf is None else cf.f_globals globalCompleter = Completer(globaldict).complete self.__getCompletionList(text, globalCompleter, completions) @@ -2041,10 +2016,7 @@ port = os.getenv('ERICPORT', 42424) remoteAddress = self.__resolveHost(host) - if filename is not None: - name = os.path.basename(filename) - else: - name = "" + name = os.path.basename(filename) if filename is not None else "" self.connectDebugger(port, remoteAddress, redirect, name=name) if filename is not None: self.running = os.path.abspath(filename) @@ -2171,10 +2143,11 @@ }) else: code = self.__compileFileSource(self.running) - if code: - res = self.mainThread.run(code, self.debugMod.__dict__, debug=True) - else: - res = 42 # should not happen + res = ( + self.mainThread.run(code, self.debugMod.__dict__, debug=True) + if code else + 42 # should not happen + ) return res def run_call(self, scriptname, func, *args): @@ -2202,10 +2175,7 @@ host, version = host.split("@@") except ValueError: version = 'v4' - if version == 'v4': - family = socket.AF_INET - else: - family = socket.AF_INET6 + family = socket.AF_INET if version == 'v4' else socket.AF_INET6 retryCount = 0 while retryCount < 10: @@ -2328,11 +2298,8 @@ redirect = True ipOrHost = sys.argv[3] - if ':' in ipOrHost: - # IPv6 address - remoteAddress = ipOrHost - elif ipOrHost[0] in '0123456789': - # IPv4 address + if ':' in ipOrHost or ipOrHost[0] in '0123456789': + # IPv6 address or IPv4 address remoteAddress = ipOrHost else: remoteAddress = self.__resolveHost(ipOrHost) @@ -2397,8 +2364,5 @@ @return flag indicating eligibility @rtype bool """ - for pattern in self.noDebugList: - if fnmatch.fnmatch(scriptName, pattern): - return True - - return False + return any(fnmatch.fnmatch(scriptName, pattern) + for pattern in self.noDebugList)