eric6/DebugClients/Python/DebugVariables.py

branch
Variables Viewer
changeset 6988
87ad87ef1910
parent 6978
720247f98e1f
child 7250
d8bdc55aee1a
--- a/eric6/DebugClients/Python/DebugVariables.py	Sun Apr 28 11:14:43 2019 +0200
+++ b/eric6/DebugClients/Python/DebugVariables.py	Thu May 02 22:58:33 2019 +0200
@@ -247,6 +247,40 @@
     
 
 ############################################################
+## Resolver for dict_items, dict_keys and dict_values
+############################################################
+
+
+class DictViewResolver(ListResolver):
+    """
+    Class used to resolve from dict views.
+    """
+    def resolve(self, var, attribute):
+        """
+        Public method to get an attribute from a variable.
+        
+        @param var variable to extract an attribute or value from
+        @type tuple or list
+        @param attribute id of the value to extract
+        @type str
+        @return value of the attribute
+        @rtype any
+        """
+        return super(DictViewResolver, self).resolve(list(var), attribute)
+    
+    def getDictionary(self, var):
+        """
+        Public method to get the attributes of a variable as a dictionary.
+        
+        @param var variable to be converted
+        @type any
+        @return dictionary containing the variable attributes
+        @rtype dict
+        """
+        return super(DictViewResolver, self).getDictionary(list(var))
+
+
+############################################################
 ## Resolver for Sets and Frozensets
 ############################################################
 
@@ -580,6 +614,7 @@
 defaultResolver = DefaultResolver()
 dictResolver = DictResolver()
 listResolver = ListResolver()
+dictViewResolver = DictViewResolver()
 setResolver = SetResolver()
 ndarrayResolver = NdArrayResolver()
 multiValueDictResolver = MultiValueDictResolver()
@@ -615,12 +650,12 @@
     try:
         _TypeMap.append((long, None))           # __IGNORE_WARNING__
     except Exception:
-        pass    # not available on all python versions
+        pass    # not available on all Python versions
 
     try:
         _TypeMap.append((unicode, None))        # __IGNORE_WARNING__
     except Exception:
-        pass    # not available on all python versions
+        pass    # not available on all Python versions
 
     try:
         import array
@@ -640,6 +675,14 @@
         _TypeMap.insert(0, (MultiValueDict, multiValueDictResolver))
     except ImportError:
         pass  # django may not be installed
+    
+    try:
+        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
 
 
 def getType(obj):

eric ide

mercurial