diff -r fb0ef164f536 -r 698ae46f40a4 eric6/DebugClients/Python/DebugVariables.py --- a/eric6/DebugClients/Python/DebugVariables.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/DebugClients/Python/DebugVariables.py Sat May 01 14:27:20 2021 +0200 @@ -7,6 +7,8 @@ Module implementing classes and functions to dump variable contents. """ +import contextlib + from DebugConfig import ConfigQtNames, ConfigKnownQtTypes, BatchSize # @@ -18,7 +20,7 @@ ############################################################ -class BaseResolver(object): +class BaseResolver: """ Base class of the resolver class tree. """ @@ -50,11 +52,9 @@ d = {} for name in names: - try: + with contextlib.suppress(Exception): attribute = getattr(var, name) d[name] = attribute - except Exception: # secok - pass # if we can't get it, simply ignore it return d @@ -84,11 +84,9 @@ d = {} for name in names: - try: + with contextlib.suppress(Exception): attribute = getattr(var, name) d[name] = attribute - except Exception: # secok - pass # if we can't get it, simply ignore it yield -1, d while True: @@ -180,7 +178,7 @@ yield start, d # in case it has additional fields - d = super(DictResolver, self).getDictionary(var) + d = super().getDictionary(var) yield -1, d while True: @@ -237,7 +235,7 @@ yield start, d # in case it has additional fields - d = super(ListResolver, self).getDictionary(var) + d = super().getDictionary(var) yield -1, d while True: @@ -264,7 +262,7 @@ @return value of the attribute @rtype any """ - return super(DictViewResolver, self).resolve(list(var), attribute) + return super().resolve(list(var), attribute) def getDictionary(self, var): """ @@ -275,7 +273,7 @@ @return dictionary containing the variable attributes @rtype dict """ - return super(DictViewResolver, self).getDictionary(list(var)) + return super().getDictionary(list(var)) ############################################################ @@ -336,7 +334,7 @@ yield start, d # in case it has additional fields - additionals = super(SetResolver, self).getDictionary(var) + additionals = super().getDictionary(var) yield -1, additionals while True: @@ -433,7 +431,7 @@ yield start, d # in case it has additional fields - d = super(NdArrayResolver, self).getDictionary(var) + d = super().getDictionary(var) if var.size > 1024 * 1024: d['min'] = ( @@ -489,7 +487,7 @@ return getattr(var, attribute, None) expectedID = int(attribute.split(" (ID:")[-1][:-1]) - for key in var.keys(): + for key in var: if id(key) == expectedID: return var.getlist(key) @@ -529,7 +527,7 @@ yield start, d # in case it has additional fields - d = super(DictResolver, self).getDictionary(var) + d = super().getDictionary(var) yield -1, d while True: @@ -606,7 +604,7 @@ yield start, d # in case it has additional fields - d = super(ArrayResolver, self).getDictionary(var) + d = super().getDictionary(var) # Special data for array type: convert typecode to readable text d['type'] = self.TypeCodeMap.get(var.typecode, 'illegal type') @@ -653,37 +651,31 @@ (frozenset, setResolver), ] - try: + with contextlib.suppress(Exception): _TypeMap.append((long, None)) # __IGNORE_WARNING__ - except Exception: # secok - pass # not available on all Python versions - try: + with contextlib.suppress(ImportError): import array _TypeMap.append((array.array, arrayResolver)) - except ImportError: - pass # array.array may not be available + # array.array may not be available - try: + with contextlib.suppress(ImportError): import numpy _TypeMap.append((numpy.ndarray, ndarrayResolver)) - except ImportError: - pass # numpy may not be installed + # numpy may not be installed - try: + with contextlib.suppress(ImportError): from django.utils.datastructures import MultiValueDict # it should go before dict _TypeMap.insert(0, (MultiValueDict, multiValueDictResolver)) - except ImportError: - pass # django may not be installed + # django may not be installed - try: + with contextlib.suppress(ImportError): from collections.abc import ItemsView, KeysView, ValuesView _TypeMap.append((ItemsView, dictViewResolver)) _TypeMap.append((KeysView, dictViewResolver)) _TypeMap.append((ValuesView, dictViewResolver)) - except ImportError: - pass # not available on all Python versions + # not available on all Python versions def getType(obj): @@ -717,3 +709,6 @@ resolver = defaultResolver return typeName, typeStr, resolver + +# +# eflag: noqa = Y113