Debugger: changed the handling of variable type filters.

Sun, 06 Dec 2020 17:43:11 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 06 Dec 2020 17:43:11 +0100
changeset 7862
817ef8e0fa66
parent 7861
3d48094ba8e1
child 7863
6725d2549801
child 7865
393b25ccb048

Debugger: changed the handling of variable type filters.

eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugConfig.py file | annotate | diff | comparison | revisions
eric6/DebugClients/Python/DebugVariables.py file | annotate | diff | comparison | revisions
eric6/Debugger/Config.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebugServer.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebugUI.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebugViewer.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebuggerInterfaceNone.py file | annotate | diff | comparison | revisions
eric6/Debugger/DebuggerInterfacePython.py file | annotate | diff | comparison | revisions
eric6/Debugger/VariablesFilterDialog.py file | annotate | diff | comparison | revisions
eric6/Debugger/VariablesViewer.py file | annotate | diff | comparison | revisions
eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py file | annotate | diff | comparison | revisions
--- a/eric6/DebugClients/Python/DebugClientBase.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Sun Dec 06 17:43:11 2020 +0100
@@ -27,7 +27,7 @@
 import DebugVariables
 from DebugBase import setRecursionLimit, printerr   # __IGNORE_WARNING__
 from AsyncFile import AsyncFile, AsyncPendingWrite
-from DebugConfig import ConfigQtNames, ConfigVarTypeStrings
+from DebugConfig import ConfigQtNames, SpecialAttributes
 from FlexCompleter import Completer
 from DebugUtilities import prepareJsonCommand
 from BreakpointWatch import Breakpoint, Watch
@@ -1409,8 +1409,8 @@
         @type int
         @param scope 1 to report global variables, 0 for local variables
         @type int
-        @param filterList the indices of variable types to be filtered
-        @type list of int
+        @param filterList list of variable types to be filtered
+        @type list of str
         """
         if self.currentThread is None:
             return
@@ -1458,7 +1458,7 @@
         @type int
         @param scope 1 to report global variables, 0 for local variables
         @type int
-        @param filterList the indices of variable types to be filtered
+        @param filterList list of variable types to be filtered
         @type list of int
         """
         if self.currentThread is None:
@@ -1714,10 +1714,10 @@
             Variables are only added to the list, if their name do not match
             any of the filter expressions.
         @type int
-        @param filterList the indices of variable types to be filtered.
+        @param filterList list of variable types to be filtered.
             Variables are only added to the list, if their type is not
             contained in the filter list.
-        @type list of int
+        @type list of str
         @return A tuple consisting of a list of formatted variables. Each
             variable entry is a tuple of three elements, the variable name,
             its type and value.
@@ -1748,15 +1748,25 @@
                 continue
             
             # filter hidden attributes (filter #0)
-            if 0 in filterList and str(key)[:2] == '__':
+            if '__' in filterList and str(key)[:2] == '__':
                 continue
             
             # special handling for '__builtins__' (it's way too big)
             if key == '__builtins__':
                 rvalue = '<module builtins (built-in)>'
                 valtype = 'module'
-                if ConfigVarTypeStrings.index(valtype) in filterList:
+                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
+            ):
+                continue
             else:
                 isQt = False
                 # valtypestr, e.g. class 'PyQt5.QtCore.QPoint'
@@ -1767,37 +1777,43 @@
                 # Strip 'instance' to be equal with Python 3
                 if valtype == "instancemethod":
                     valtype = "method"
-                elif valtype == "type" or valtype == "classobj":
+                elif valtype in ("type", "classobj"):
                     valtype = "class"
+                elif valtype == "method-wrapper":
+                    valtype = "builtin_function_or_method"
                 
                 # valtypename, e.g. QPoint
                 valtypename = type(value).__name__
-                try:
-                    if ConfigVarTypeStrings.index(valtype) in filterList:
-                        continue
-                except ValueError:
-                    if valtype in ("sip.enumtype", "sip.wrappertype"):
-                        if ConfigVarTypeStrings.index('class') in filterList:
-                            continue
-                    elif (valtype == "sip.methoddescriptor" or
-                            valtype == "method_descriptor"):
-                        if ConfigVarTypeStrings.index('method') in filterList:
-                            continue
-                    elif valtype in ("numpy.ndarray", "array.array"):
-                        if ConfigVarTypeStrings.index('list') in filterList:
-                            continue
-                    elif valtypename == "MultiValueDict":
-                        if ConfigVarTypeStrings.index('dict') in filterList:
-                            continue
-                    elif ConfigVarTypeStrings.index('instance') in filterList:
-                        continue
-                    
-                    isQt = valtype.startswith(ConfigQtNames)
-                    if (not valtypestr.startswith('type ') and
-                        valtypename not in ("ndarray", "MultiValueDict",
-                                            "array", "defaultdict") and
-                            not isQt):
-                        valtype = valtypestr
+                if valtype in filterList:
+                    continue
+                elif (
+                    valtype in ("sip.enumtype", "sip.wrappertype") and
+                    'class' in filterList
+                ):
+                    continue
+                elif (
+                    valtype in (
+                        "sip.methoddescriptor", "method_descriptor") and
+                    'method' 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)
+                # TODO: see if this is still needed
+#                if (not valtypestr.startswith('type ') and
+#                    valtypename not in ("ndarray", "MultiValueDict",
+#                                        "array", "defaultdict") and
+#                        not isQt):
+#                    valtype = valtypestr
                 
                 try:
                     if valtype in self.arrayTypes:
--- a/eric6/DebugClients/Python/DebugConfig.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/DebugClients/Python/DebugConfig.py	Sun Dec 06 17:43:11 2020 +0100
@@ -7,20 +7,11 @@
 Module defining type strings for the different Python types.
 """
 
-#
-# Keep this list in sync with Debugger.Config.ConfigVarTypeFilters
-#
-ConfigVarTypeStrings = [
-    '__', 'NoneType', 'type',
-    'bool', 'int', 'long', 'float', 'complex',
-    'str', 'unicode', 'tuple', 'list',
-    'dict', 'dict-proxy', 'set', 'file', 'xrange',
-    'slice', 'buffer', 'class', 'instance',
-    'method', 'property', 'generator',
-    'function', 'builtin_function_or_method', 'code', 'module',
-    'ellipsis', 'traceback', 'frame', 'other', 'frozenset', 'bytes',
-]
 
+SpecialAttributes = (
+    "__bases__", "__class__", "__dict__", "__doc__", "__mro__", "__name__",
+    "__qualname__",
+)
 BatchSize = 200
 ConfigQtNames = (
     'PyQt5.', 'PySide2.', 'Shiboken.EnumType'
--- a/eric6/DebugClients/Python/DebugVariables.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/DebugClients/Python/DebugVariables.py	Sun Dec 06 17:43:11 2020 +0100
@@ -138,9 +138,9 @@
         """
         if isinstance(key, str):
             key = repr(key)
-            # Special handling for Python2 unicode strings and bytes object
-            # Raw and f-Strings are always converted to (unicode) str
-            if key[0] in 'ub':
+            # Special handling for bytes object
+            # Raw and f-Strings are always converted to str
+            if key[0] == 'b':
                 key = key[1:]
 
         return key  # __IGNORE_WARNING_M834__
@@ -652,11 +652,6 @@
         pass    # not available on all Python versions
 
     try:
-        _TypeMap.append((unicode, None))        # __IGNORE_WARNING__
-    except Exception:       # secok
-        pass    # not available on all Python versions
-
-    try:
         import array
         _TypeMap.append((array.array, arrayResolver))
     except ImportError:
--- a/eric6/Debugger/Config.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/Config.py	Sun Dec 06 17:43:11 2020 +0100
@@ -9,7 +9,7 @@
 
 from PyQt5.QtCore import QT_TRANSLATE_NOOP
 
-# Variables type definition
+# Variable type definitions
 ConfigVarTypeDispStrings = {
     '__': QT_TRANSLATE_NOOP('Variable Types', 'Hidden Attributes'),
     'NoneType': QT_TRANSLATE_NOOP('Variable Types', 'None'),
@@ -20,7 +20,6 @@
     'float': QT_TRANSLATE_NOOP('Variable Types', 'Float'),
     'complex': QT_TRANSLATE_NOOP('Variable Types', 'Complex'),
     'str': QT_TRANSLATE_NOOP('Variable Types', 'String'),
-    'unicode': QT_TRANSLATE_NOOP('Variable Types', 'Unicode String'),
     'tuple': QT_TRANSLATE_NOOP('Variable Types', 'Tuple'),
     'list': QT_TRANSLATE_NOOP('Variable Types', 'List/Array'),
     'dict': QT_TRANSLATE_NOOP('Variable Types', 'Dictionary/Hash/Map'),
@@ -45,42 +44,6 @@
     'traceback': QT_TRANSLATE_NOOP('Variable Types', 'Traceback'),
     'frame': QT_TRANSLATE_NOOP('Variable Types', 'Frame'),
     'bytes': QT_TRANSLATE_NOOP('Variable Types', 'Bytes'),
+    "special_attributes": QT_TRANSLATE_NOOP(
+        'Variable Types', "Special Attributes"),
 }
-
-
-ConfigVarTypeFilters = {
-    '__': 0,
-    'NoneType': 1,
-    'type': 2,
-    'bool': 3,
-    'int': 4,
-    'long': 5,
-    'float': 6,
-    'complex': 7,
-    'str': 8,
-    'unicode': 9,  # Not used anymore but keep to avoid reassignment
-    'tuple': 10,
-    'list': 11,
-    'dict': 12,
-    'dict-proxy': 13,
-    'set': 14,
-    'file': 15,
-    'xrange': 16,
-    'slice': 17,
-    'buffer': 18,
-    'class': 19,
-    'instance': 20,
-    'method': 21,
-    'property': 22,
-    'generator': 23,
-    'function': 24,
-    'builtin_function_or_method': 25,
-    'code': 26,
-    'module': 27,
-    'ellipsis': 28,
-    'traceback': 29,
-    'frame': 30,
-    'other': 31,  # Not used anymore but keep to avoid reassignment
-    'frozenset': 32,
-    'bytes': 33,
-}
--- a/eric6/Debugger/DebugServer.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/DebugServer.py	Sun Dec 06 17:43:11 2020 +0100
@@ -1242,8 +1242,11 @@
         Public method to request the variables of the debugged program.
         
         @param scope the scope of the variables (0 = local, 1 = global)
-        @param filterList list of variable types to filter out (list of int)
-        @param framenr framenumber of the variables to retrieve (int)
+        @type int
+        @param filterList list of variable types to filter out
+        @type list of str
+        @param framenr framenumber of the variables to retrieve
+        @type int
         """
         self.debuggerInterface.remoteClientVariables(
             scope, filterList, framenr, self.__maxVariableSize)
@@ -1253,9 +1256,13 @@
         Public method to request the variables of the debugged program.
         
         @param scope the scope of the variables (0 = local, 1 = global)
-        @param filterList list of variable types to filter out (list of int)
-        @param var list encoded name of variable to retrieve (string)
-        @param framenr framenumber of the variables to retrieve (int)
+        @type int
+        @param filterList list of variable types to filter out
+        @type list of str
+        @param var list encoded name of variable to retrieve
+        @type str
+        @param framenr framenumber of the variables to retrieve
+        @type int
         """
         self.debuggerInterface.remoteClientVariable(
             scope, filterList, var, framenr, self.__maxVariableSize)
--- a/eric6/Debugger/DebugUI.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/DebugUI.py	Sun Dec 06 17:43:11 2020 +0100
@@ -115,10 +115,10 @@
             self.__continue, self.__step, self.__stepOver, self.__stepOut,
             self.__stepQuit, self.__runToCursor, self.__moveInstructionPointer
         ]
-        self.localsVarFilter, self.globalsVarFilter = (
+        self.__localsVarFilterList, self.__globalsVarFilterList = (
             Preferences.getVarFilters())
         self.debugViewer.setVariablesFilter(
-            self.globalsVarFilter, self.localsVarFilter)
+            self.__globalsVarFilterList, self.__localsVarFilterList)
         
         # Connect the signals emitted by the debug-server
         debugServer.clientGone.connect(self.__clientGone)
@@ -158,12 +158,13 @@
         Public method to get the variables filter for a scope.
         
         @param scope flag indicating global (True) or local (False) scope
-        @return filters list (list of integers)
+        @return filters list
+        @rtype list of str
         """
         if scope:
-            return self.globalsVarFilter[:]
+            return self.__globalsVarFilterList[:]
         else:
-            return self.localsVarFilter[:]
+            return self.__localsVarFilterList[:]
         
     def initActions(self):
         """
@@ -1282,7 +1283,7 @@
         """
         Private method to handle a change of the client's current thread.
         """
-        self.debugServer.remoteClientVariables(0, self.localsVarFilter)
+        self.debugServer.remoteClientVariables(0, self.__localsVarFilterList)
         
     def __getClientVariables(self):
         """
@@ -1293,7 +1294,7 @@
         This happens in the method '__clientVariables'.
         """
         # get globals first
-        self.debugServer.remoteClientVariables(1, self.globalsVarFilter)
+        self.debugServer.remoteClientVariables(1, self.__globalsVarFilterList)
         # the local variables are requested once we have received the globals
         
     def __clientVariables(self, scope, variables):
@@ -1309,7 +1310,8 @@
             self.debugViewer.showVariables(variables, True)
             if scope == 1:
                 # now get the local variables
-                self.debugServer.remoteClientVariables(0, self.localsVarFilter)
+                self.debugServer.remoteClientVariables(
+                    0, self.__localsVarFilterList)
         elif scope == 0:
             self.debugViewer.showVariables(variables, False)
         elif scope == -1:
@@ -1435,11 +1437,14 @@
         """
         from .VariablesFilterDialog import VariablesFilterDialog
         dlg = VariablesFilterDialog(self.ui, 'Filter Dialog', True)
-        dlg.setSelection(self.localsVarFilter, self.globalsVarFilter)
+        dlg.setSelection(self.__localsVarFilterList,
+                         self.__globalsVarFilterList)
         if dlg.exec() == QDialog.Accepted:
-            self.localsVarFilter, self.globalsVarFilter = dlg.getSelection()
+            self.__localsVarFilterList, self.__globalsVarFilterList = (
+                dlg.getSelection()
+            )
             self.debugViewer.setVariablesFilter(
-                self.globalsVarFilter, self.localsVarFilter)
+                self.__globalsVarFilterList, self.__localsVarFilterList)
 
     def __configureExceptionsFilter(self):
         """
--- a/eric6/Debugger/DebugViewer.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/DebugViewer.py	Sun Dec 06 17:43:11 2020 +0100
@@ -384,11 +384,12 @@
         Public slot to set the local variables filter.
         
         @param globalsFilter filter list for global variable types
-            (list of int)
-        @param localsFilter filter list for local variable types (list of int)
+        @type list of str
+        @param localsFilter filter list for local variable types
+        @type list of str
         """
-        self.globalsFilter = globalsFilter
-        self.localsFilter = localsFilter
+        self.__globalsFilter = globalsFilter
+        self.__localsFilter = localsFilter
         
     def __showSource(self):
         """
@@ -408,7 +409,8 @@
         """
         self.framenr = frmnr
         if self.debugServer.isDebugging():
-            self.debugServer.remoteClientVariables(0, self.localsFilter, frmnr)
+            self.debugServer.remoteClientVariables(
+                0, self.__localsFilter, frmnr)
         
         if self.__autoViewSource:
             self.__showSource()
@@ -420,7 +422,7 @@
         if self.debugServer.isDebugging():
             filterStr = self.globalsFilterEdit.text()
             self.debugServer.remoteClientSetFilter(1, filterStr)
-            self.debugServer.remoteClientVariables(2, self.globalsFilter)
+            self.debugServer.remoteClientVariables(2, self.__globalsFilter)
         
     def setLocalsFilter(self):
         """
@@ -431,7 +433,7 @@
             self.debugServer.remoteClientSetFilter(0, filterStr)
             if self.currentStack:
                 self.debugServer.remoteClientVariables(
-                    0, self.localsFilter, self.framenr)
+                    0, self.__localsFilter, self.framenr)
         
     def handleDebuggingStarted(self):
         """
--- a/eric6/Debugger/DebuggerInterfaceNone.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/DebuggerInterfaceNone.py	Sun Dec 06 17:43:11 2020 +0100
@@ -328,7 +328,7 @@
         @param scope the scope of the variables (0 = local, 1 = global)
         @type int
         @param filterList list of variable types to filter out
-        @type list of int
+        @type list of str
         @param framenr framenumber of the variables to retrieve
         @type int
         @param maxSize maximum size the formatted value of a variable will
@@ -346,7 +346,7 @@
         @param scope the scope of the variables (0 = local, 1 = global)
         @type int
         @param filterList list of variable types to filter out
-        @type list of int
+        @type list of str
         @param var list encoded name of variable to retrieve
         @type list of str
         @param framenr framenumber of the variables to retrieve (int)
--- a/eric6/Debugger/DebuggerInterfacePython.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/DebuggerInterfacePython.py	Sun Dec 06 17:43:11 2020 +0100
@@ -817,7 +817,7 @@
         @param scope the scope of the variables (0 = local, 1 = global)
         @type int
         @param filterList list of variable types to filter out
-        @type list of int
+        @type list of str
         @param framenr framenumber of the variables to retrieve
         @type int
         @param maxSize maximum size the formatted value of a variable will
@@ -840,7 +840,7 @@
         @param scope the scope of the variables (0 = local, 1 = global)
         @type int
         @param filterList list of variable types to filter out
-        @type list of int
+        @type list of str
         @param var list encoded name of variable to retrieve
         @type list of str
         @param framenr framenumber of the variables to retrieve
@@ -1039,7 +1039,7 @@
                 encoding=Preferences.getSystem("StringEncoding"))
             
             logging.debug("<Debug-Server> %s", line)
-##            print("Server: ", line)          ##debug
+            print("Server: ", line)          ##debug
             
             self.__handleJsonCommand(line)
             continue
--- a/eric6/Debugger/VariablesFilterDialog.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/VariablesFilterDialog.py	Sun Dec 06 17:43:11 2020 +0100
@@ -10,7 +10,7 @@
 from PyQt5.QtCore import Qt
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem
 
-from Debugger.Config import ConfigVarTypeDispStrings, ConfigVarTypeFilters
+from Debugger.Config import ConfigVarTypeDispStrings
 import Preferences
 
 from .Ui_VariablesFilterDialog import Ui_VariablesFilterDialog
@@ -44,7 +44,7 @@
         for widget in self.localsList, self.globalsList:
             for varType, varTypeStr in ConfigVarTypeDispStrings.items():
                 itm = QListWidgetItem(self.tr(varTypeStr), widget)
-                itm.setData(Qt.UserRole, ConfigVarTypeFilters[varType])
+                itm.setData(Qt.UserRole, varType)
                 itm.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
                 itm.setCheckState(Qt.Unchecked)
                 widget.addItem(itm)
@@ -56,8 +56,10 @@
         """
         Public slot to retrieve the current selections.
         
-        @return A tuple of lists of integer values. The first list is the
-            locals variables filter, the second the globals variables filter.
+        @return tuple of lists containing the variable filters. The first list
+            is the locals variables filter, the second the globals variables
+            filter.
+        @rtype tuple of (list of str, list of str)
         """
         lList = []
         for row in range(self.localsList.count()):
@@ -76,8 +78,10 @@
         """
         Public slot to set the current selection.
         
-        @param lList local variables filter (list of int)
-        @param gList global variables filter (list of int)
+        @param lList local variables filter
+        @type list of str
+        @param gList global variables filter
+        @type list of str
         """
         for row in range(self.localsList.count()):
             itm = self.localsList.item(row)
--- a/eric6/Debugger/VariablesViewer.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Debugger/VariablesViewer.py	Sun Dec 06 17:43:11 2020 +0100
@@ -195,7 +195,7 @@
         elif dtype == "Shiboken.EnumType":
             self.hasChildren = True
             
-        elif dtype in ['str', 'unicode']:
+        elif dtype == 'str':
             if VariableItem.rx_nonprintable.search(dvalue) is None:
                 try:
                     dvalue = ast.literal_eval(dvalue)
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py	Sun Dec 06 12:46:00 2020 +0100
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py	Sun Dec 06 17:43:11 2020 +0100
@@ -146,10 +146,9 @@
     @property
     def stringVal(self):
         """
-        Public method to get the value of a standalone unicode or string
-        object.
+        Public method to get the value of a standalone string object.
         
-        @return value of a standalone unicode or string object
+        @return value of a standalone string object
         @rtype str
         """
         return self.__context.get('str')

eric ide

mercurial