eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py

changeset 7637
c878e8255972
parent 7628
f904d0eef264
child 7639
422fd05e9c91
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py	Mon Jun 22 17:55:06 2020 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py	Tue Jun 23 17:24:18 2020 +0200
@@ -40,11 +40,7 @@
         @param startLine line number the context starts in the source (integer)
         @param contextType type of the context object (string)
         """
-        if sys.version_info[0] == 2:
-            stringTypes = (str, unicode)        # __IGNORE_WARNING__
-        else:
-            stringTypes = str
-        if isinstance(source, stringTypes):
+        if isinstance(source, str):
             self.__source = source.splitlines(True)
         else:
             self.__source = source[:]
@@ -360,12 +356,6 @@
             return
         
         source = "".join(self.__source)
-        # Check type for py2: if not str it's unicode
-        if sys.version_info[0] == 2:
-            try:
-                source = source.encode('utf-8')
-            except UnicodeError:
-                pass
         try:
             compile(source, self.__filename, 'exec', ast.PyCF_ONLY_AST)
         except (SyntaxError, TypeError):
@@ -445,62 +435,30 @@
             summaries.append(line2)
         return summaries, lineno
     
-    if sys.version_info[0] < 3:
-        def __getArgNames(self, node):
-            """
-            Private method to get the argument names of a function node.
-            
-            @param node AST node to extract arguments names from
-            @return tuple of two list of argument names, one for arguments
-                and one for keyword arguments (tuple of list of string)
-            """
-            def unpackArgs(args):
-                """
-                Local helper function to unpack function argument names.
-                
-                @param args list of AST node arguments
-                @return list of argument names (list of string)
-                """
-                ret = []
-                for arg in args:
-                    if isinstance(arg, ast.Tuple):
-                        ret.extend(unpackArgs(arg.elts))
-                    else:
-                        ret.append(arg.id)
-                return ret
-            
-            arguments = unpackArgs(node.args.args)
-            if node.args.vararg is not None:
+    def __getArgNames(self, node):
+        """
+        Private method to get the argument names of a function node.
+        
+        @param node AST node to extract arguments names from
+        @return tuple of two list of argument names, one for arguments
+            and one for keyword arguments (tuple of list of string)
+        """
+        arguments = []
+        arguments.extend([arg.arg for arg in node.args.args])
+        if node.args.vararg is not None:
+            if sys.version_info < (3, 4, 0):
                 arguments.append(node.args.vararg)
-            kwarguments = []
-            if node.args.kwarg is not None:
+            else:
+                arguments.append(node.args.vararg.arg)
+        
+        kwarguments = []
+        kwarguments.extend([arg.arg for arg in node.args.kwonlyargs])
+        if node.args.kwarg is not None:
+            if sys.version_info < (3, 4, 0):
                 kwarguments.append(node.args.kwarg)
-            return arguments, kwarguments
-    else:
-        def __getArgNames(self, node):          # __IGNORE_WARNING__
-            """
-            Private method to get the argument names of a function node.
-            
-            @param node AST node to extract arguments names from
-            @return tuple of two list of argument names, one for arguments
-                and one for keyword arguments (tuple of list of string)
-            """
-            arguments = []
-            arguments.extend([arg.arg for arg in node.args.args])
-            if node.args.vararg is not None:
-                if sys.version_info < (3, 4, 0):
-                    arguments.append(node.args.vararg)
-                else:
-                    arguments.append(node.args.vararg.arg)
-            
-            kwarguments = []
-            kwarguments.extend([arg.arg for arg in node.args.kwonlyargs])
-            if node.args.kwarg is not None:
-                if sys.version_info < (3, 4, 0):
-                    kwarguments.append(node.args.kwarg)
-                else:
-                    kwarguments.append(node.args.kwarg.arg)
-            return arguments, kwarguments
+            else:
+                kwarguments.append(node.args.kwarg.arg)
+        return arguments, kwarguments
     
     ##################################################################
     ## Parsing functionality below

eric ide

mercurial