]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenDepex.py
BaseTools: Fix old python2 idioms
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenDepex.py
index 23b289500e014a8f6f395c6bb1c28930390a8c6b..e89191a72b9fcc2c408bc252ddae16c1a3e78a19 100644 (file)
@@ -140,7 +140,7 @@ class DependencyExpression:
     def __init__(self, Expression, ModuleType, Optimize=False):\r
         self.ModuleType = ModuleType\r
         self.Phase = gType2Phase[ModuleType]\r
-        if type(Expression) == type([]):\r
+        if isinstance(Expression, type([])):\r
             self.ExpressionString = " ".join(Expression)\r
             self.TokenList = Expression\r
         else:\r
@@ -271,10 +271,14 @@ class DependencyExpression:
 \r
     ## Simply optimize the dependency expression by removing duplicated operands\r
     def Optimize(self):\r
-        ValidOpcode = list(set(self.OpcodeList))\r
-        if len(ValidOpcode) != 1 or ValidOpcode[0] not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]:\r
+        OpcodeSet = set(self.OpcodeList)\r
+        # if there are isn't one in the set, return\r
+        if len(OpcodeSet) != 1:\r
+          return\r
+        Op = OpcodeSet.pop()\r
+        #if Op isn't either OR or AND, return\r
+        if Op not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]:\r
             return\r
-        Op = ValidOpcode[0]\r
         NewOperand = []\r
         AllOperand = set()\r
         for Token in self.PostfixNotation:\r
@@ -445,7 +449,7 @@ def Main():
                     os.utime(Option.OutputFile, None)\r
         else:\r
             Dpx.Generate()\r
-    except BaseException, X:\r
+    except BaseException as X:\r
         EdkLogger.quiet("")\r
         if Option is not None and Option.debug is not None:\r
             EdkLogger.quiet(traceback.format_exc())\r