Fixed an issue causing list, set, dict and tuple derived classes not being handled correctly in the Variables Viewer (issue393). eric7

Sat, 19 Jun 2021 16:22:11 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 19 Jun 2021 16:22:11 +0200
branch
eric7
changeset 8433
91d5ffe55839
parent 8432
074407b4c107
child 8435
f3554a0a34ca

Fixed an issue causing list, set, dict and tuple derived classes not being handled correctly in the Variables Viewer (issue393).

eric7/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric7/Debugger/VariablesViewer.py file | annotate | diff | comparison | revisions
--- a/eric7/DebugClients/Python/DebugClientBase.py	Sat Jun 19 12:17:17 2021 +0200
+++ b/eric7/DebugClients/Python/DebugClientBase.py	Sat Jun 19 16:22:11 2021 +0200
@@ -1594,7 +1594,7 @@
                     varlist = self.__formatVariablesList(
                         varDict, scope, filterList)
                 else:
-                    # Gently handle exception which could occure as special
+                    # Gently handle exception which could occur as special
                     # cases, e.g. already deleted C++ objects, str conversion..
                     try:
                         varlist = self.__formatQtVariable(variable, typeName)
@@ -1881,8 +1881,11 @@
                         rvalue = "{0:d}|{1}".format(
                             len(value), value.typecode)
                     elif valtype == 'collections.defaultdict':
-                        rvalue = "{0:d}|{1}".format(
-                            len(value), value.default_factory.__name__)
+                        if value.default_factory is None:
+                            factoryName = "None"
+                        else:
+                            factoryName = value.default_factory.__name__
+                        rvalue = "{0:d}|{1}".format(len(value), factoryName)
                     elif valtype == "numpy.ndarray":
                         rvalue = "x".join(str(x) for x in value.shape)
                     elif valtypename == "MultiValueDict":
--- a/eric7/Debugger/VariablesViewer.py	Sat Jun 19 12:17:17 2021 +0200
+++ b/eric7/Debugger/VariablesViewer.py	Sat Jun 19 16:22:11 2021 +0200
@@ -196,16 +196,38 @@
             self.childCount = int(dvalue)
             dvalue = VariableItem.noOfItemsStr.format(dvalue)
             self.hasChildren = True
-            
+        
         elif dtype == "Shiboken.EnumType":
             self.hasChildren = True
-            
+        
         elif dtype == 'str':
             if VariableItem.rx_nonprintable.search(dvalue) is None:
                 with contextlib.suppress(Exception):
                     dvalue = ast.literal_eval(dvalue)
             dvalue = str(dvalue)
         
+        elif (
+            dvalue.startswith(("{", "(", "[")) and
+            dvalue.endswith(("}", ")", "]"))
+        ):
+            # it is most probably a dict, tuple or list derived class
+            value = ast.literal_eval(dvalue)
+            valueTypeStr = str(type(value))[8:-2]
+            if valueTypeStr in VariableItem.arrayTypes:
+                self.childCount = len(value)
+                self.hasChildren = True
+        
+        elif (
+            (dvalue.endswith("})") and "({" in dvalue) or
+            (dvalue.endswith("])") and "([" in dvalue)
+        ):
+            # that is probably a set derived class
+            value = ast.literal_eval(dvalue.split("(", 1)[1][:-1])
+            valueTypeStr = str(type(value))[8:-2]
+            if valueTypeStr in VariableItem.arrayTypes:
+                self.childCount = len(value)
+                self.hasChildren = True
+        
         self.value = dvalue
         
         if len(dvalue) > 2048:     # 2 kB

eric ide

mercurial