eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8205
4a0f1f896341
diff -r fb0ef164f536 -r 698ae46f40a4 eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py	Sat May 01 14:27:20 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