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

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

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 19 Jun 2021 16:22:11 +0200
changeset 8434
a105f31ba10f
parent 8429
ab23dbabd491
child 8436
f22f8d8337b8

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

eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric6/Debugger/VariablesViewer.py file | annotate | diff | comparison | revisions
--- a/eric6/DebugClients/Python/DebugClientBase.py	Wed Jun 16 19:06:47 2021 +0200
+++ b/eric6/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/eric6/Debugger/VariablesViewer.py	Wed Jun 16 19:06:47 2021 +0200
+++ b/eric6/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