eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py

changeset 8205
4a0f1f896341
parent 7923
91e843545d9a
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py	Thu Apr 08 17:27:12 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py	Thu Apr 08 18:27:47 2021 +0200
@@ -96,10 +96,10 @@
         @rtype any
         @exception TypeError raised to indicate an unsupported type
         """
-        if isinstance(node, ast.Constant):
-            return node.value
-        else:
+        if not isinstance(node, ast.Constant):
             raise TypeError("Illegal node type passed.")
+        
+        return node.value
 
 else:
     # functions for Python < 3.8
@@ -169,17 +169,18 @@
         @rtype one of str, bytes, int
         @exception TypeError raised to indicate an unsupported type
         """
+        if not isinstance(
+            node, (ast.Num, ast.Str, ast.Bytes, ast.NameConstant)
+        ):
+            raise TypeError("Illegal node type passed.")
+        
         if isinstance(node, ast.Num):
             return node.n
         
-        elif isinstance(node, ast.Str):
-            return node.s
-        
-        elif isinstance(node, ast.Bytes):
+        elif isinstance(node, (ast.Str, ast.Bytes)):
             return node.s
         
         elif isinstance(node, ast.NameConstant):
             return node.value
         
-        else:
-            raise TypeError("Illegal node type passed.")
+        return None

eric ide

mercurial