From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=195.135.221.5; helo=smtp.nue.novell.com; envelope-from=glin@suse.com; receiver=edk2-devel@lists.01.org Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A3F9021E0B9E2 for ; Thu, 1 Feb 2018 00:31:31 -0800 (PST) Received: from localhost.localdomain (unknown.telstraglobal.net [134.159.103.118]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Thu, 01 Feb 2018 09:37:05 +0100 From: Gary Lin To: edk2-devel@lists.01.org Cc: Yonghong Zhu , Liming Gao Date: Thu, 1 Feb 2018 16:36:02 +0800 Message-Id: <20180201083608.16036-15-glin@suse.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180201083608.16036-1-glin@suse.com> References: <20180201083608.16036-1-glin@suse.com> Subject: [PATCH v2 14/20] BaseTools: Adjust old python2 idioms X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 08:31:33 -0000 Based on "futurize -f lib2to3.fixes.fix_idioms" * Change some type comparisons to isinstance() calls: type(x) == T -> isinstance(x, T) type(x) is T -> isinstance(x, T) type(x) != T -> not isinstance(x, T) type(x) is not T -> not isinstance(x, T) * Change "while 1:" into "while True:". * Change both v = list(EXPR) v.sort() foo(v) and the more general v = EXPR v.sort() foo(v) into v = sorted(EXPR) foo(v) Contributed-under: TianoCore Contribution Agreement 1.1 Cc: Yonghong Zhu Cc: Liming Gao Signed-off-by: Gary Lin --- BaseTools/Scripts/MemoryProfileSymbolGen.py | 2 +- BaseTools/Scripts/UpdateBuildVersions.py | 6 +-- BaseTools/Source/Python/AutoGen/AutoGen.py | 3 +- BaseTools/Source/Python/AutoGen/BuildEngine.py | 2 +- BaseTools/Source/Python/AutoGen/GenDepex.py | 2 +- BaseTools/Source/Python/Common/Dictionary.py | 2 +- BaseTools/Source/Python/Common/Expression.py | 46 ++++++++++---------- BaseTools/Source/Python/Common/Misc.py | 13 +++--- BaseTools/Source/Python/Common/RangeExpression.py | 16 +++---- BaseTools/Source/Python/Common/String.py | 4 +- BaseTools/Source/Python/Common/TargetTxtClassObject.py | 2 +- BaseTools/Source/Python/Common/ToolDefClassObject.py | 2 +- BaseTools/Source/Python/Common/VpdInfoFile.py | 3 +- BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py | 12 ++--- BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py | 2 +- BaseTools/Source/Python/Eot/Parser.py | 2 +- BaseTools/Source/Python/GenFds/GenFds.py | 4 +- BaseTools/Source/Python/TargetTool/TargetTool.py | 2 +- BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py | 15 +++---- BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py | 21 +++------ BaseTools/Source/Python/UPT/Library/Misc.py | 6 +-- BaseTools/Source/Python/UPT/Library/ParserValidate.py | 2 +- BaseTools/Source/Python/UPT/Library/String.py | 2 +- BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py | 2 +- BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py | 3 +- BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py | 3 +- BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py | 3 +- BaseTools/Source/Python/Workspace/BuildClassObject.py | 2 +- BaseTools/Source/Python/Workspace/DscBuildData.py | 6 +-- BaseTools/Source/Python/Workspace/MetaFileParser.py | 18 ++++---- BaseTools/Source/Python/build/BuildReport.py | 3 +- BaseTools/Source/Python/build/build.py | 4 +- BaseTools/gcc/mingw-gcc-build.py | 4 +- 33 files changed, 100 insertions(+), 119 deletions(-) diff --git a/BaseTools/Scripts/MemoryProfileSymbolGen.py b/BaseTools/Scripts/MemoryProfileSymbolGen.py index c9158800668d..b98f6dccea08 100644 --- a/BaseTools/Scripts/MemoryProfileSymbolGen.py +++ b/BaseTools/Scripts/MemoryProfileSymbolGen.py @@ -263,7 +263,7 @@ def main(): return 1 try: - while 1: + while True: line = file.readline() if not line: break diff --git a/BaseTools/Scripts/UpdateBuildVersions.py b/BaseTools/Scripts/UpdateBuildVersions.py index cff2e2263a8a..5725be57562f 100755 --- a/BaseTools/Scripts/UpdateBuildVersions.py +++ b/BaseTools/Scripts/UpdateBuildVersions.py @@ -253,7 +253,7 @@ def GetSvnRevision(opts): StatusCmd = "svn st -v --depth infinity --non-interactive" contents = ShellCommandResults(StatusCmd, opts) os.chdir(Cwd) - if type(contents) is ListType: + if isinstance(contents, ListType): for line in contents: if line.startswith("M "): Modified = True @@ -263,7 +263,7 @@ def GetSvnRevision(opts): InfoCmd = "svn info %s" % SrcPath.replace("\\", "/").strip() Revision = 0 contents = ShellCommandResults(InfoCmd, opts) - if type(contents) is IntType: + if isinstance(contents, IntType): return 0, Modified for line in contents: line = line.strip() @@ -284,7 +284,7 @@ def CheckSvn(opts): VerCmd = "svn --version" contents = ShellCommandResults(VerCmd, opts) opts.silent = OriginalSilent - if type(contents) is IntType: + if isinstance(contents, IntType): if opts.verbose: sys.stdout.write("SVN does not appear to be available.\n") sys.stdout.flush() diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index 0017f66e5ec8..5af16e6d68d7 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -1608,8 +1608,7 @@ class PlatformAutoGen(AutoGen): PcdNvStoreDfBuffer.SkuInfoList[skuname].DefaultValue = vardump PcdNvStoreDfBuffer.MaxDatumSize = str(len(vardump.split(","))) - PlatformPcds = self._PlatformPcds.keys() - PlatformPcds.sort() + PlatformPcds = sorted(self._PlatformPcds.keys()) # # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up. # diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py index e8f6788cdc40..6daff7210a37 100644 --- a/BaseTools/Source/Python/AutoGen/BuildEngine.py +++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py @@ -80,7 +80,7 @@ class TargetDescBlock(object): return hash(self.Target.Path) def __eq__(self, Other): - if type(Other) == type(self): + if isinstance(Other, type(self)): return Other.Target.Path == self.Target.Path else: return str(Other) == self.Target.Path diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py b/BaseTools/Source/Python/AutoGen/GenDepex.py index 98a43db7a4e5..0f6a1700f541 100644 --- a/BaseTools/Source/Python/AutoGen/GenDepex.py +++ b/BaseTools/Source/Python/AutoGen/GenDepex.py @@ -143,7 +143,7 @@ class DependencyExpression: def __init__(self, Expression, ModuleType, Optimize=False): self.ModuleType = ModuleType self.Phase = gType2Phase[ModuleType] - if type(Expression) == type([]): + if isinstance(Expression, type([])): self.ExpressionString = " ".join(Expression) self.TokenList = Expression else: diff --git a/BaseTools/Source/Python/Common/Dictionary.py b/BaseTools/Source/Python/Common/Dictionary.py index 5f2cc8f31ffa..c381995f97ff 100644 --- a/BaseTools/Source/Python/Common/Dictionary.py +++ b/BaseTools/Source/Python/Common/Dictionary.py @@ -69,7 +69,7 @@ def printDict(Dict): # @param key: The key of the item to be printed # def printList(Key, List): - if type(List) == type([]): + if isinstance(List, type([])): if len(List) > 0: if Key.find(TAB_SPLIT) != -1: print("\n" + Key) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index af5baeb2f5e1..3b5afdc9ab06 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -159,23 +159,23 @@ class ValueExpression(object): def Eval(Operator, Oprand1, Oprand2 = None): WrnExp = None - if Operator not in ["in", "not in"] and (type(Oprand1) == type('') or type(Oprand2) == type('')): - if type(Oprand1) == type(''): + if Operator not in ["in", "not in"] and (isinstance(Oprand1, type('')) or isinstance(Oprand2, type(''))): + if isinstance(Oprand1, type('')): if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or Oprand1.startswith("L'")or Oprand1.startswith('UINT'): Oprand1, Size = ParseFieldValue(Oprand1) else: Oprand1, Size = ParseFieldValue('"' + Oprand1 + '"') - if type(Oprand2) == type(''): + if isinstance(Oprand2, type('')): if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or Oprand2.startswith("L'") or Oprand2.startswith('UINT'): Oprand2, Size = ParseFieldValue(Oprand2) else: Oprand2, Size = ParseFieldValue('"' + Oprand2 + '"') - if type(Oprand1) == type('') or type(Oprand2) == type(''): + if isinstance(Oprand1, type('')) or isinstance(Oprand2, type('')): raise BadExpression(ERR_STRING_EXPR % Operator) if Operator in ['in', 'not in']: - if type(Oprand1) != type(''): + if not isinstance(Oprand1, type('')): Oprand1 = IntToStr(Oprand1) - if type(Oprand2) != type(''): + if not isinstance(Oprand2, type('')): Oprand2 = IntToStr(Oprand2) TypeDict = { type(0) : 0, @@ -185,18 +185,18 @@ class ValueExpression(object): EvalStr = '' if Operator in ["!", "NOT", "not"]: - if type(Oprand1) == type(''): + if isinstance(Oprand1, type('')): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr = 'not Oprand1' elif Operator in ["~"]: - if type(Oprand1) == type(''): + if isinstance(Oprand1, type('')): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr = '~ Oprand1' else: if Operator in ["+", "-"] and (type(True) in [type(Oprand1), type(Oprand2)]): # Boolean in '+'/'-' will be evaluated but raise warning WrnExp = WrnExpression(WRN_BOOL_EXPR) - elif type('') in [type(Oprand1), type(Oprand2)] and type(Oprand1)!= type(Oprand2): + elif type('') in [type(Oprand1), type(Oprand2)] and not isinstance(Oprand1, type(Oprand2)): # == between string and number/boolean will always return False, != return True if Operator == "==": WrnExp = WrnExpression(WRN_EQCMP_STR_OTHERS) @@ -217,11 +217,11 @@ class ValueExpression(object): pass else: raise BadExpression(ERR_EXPR_TYPE) - if type(Oprand1) == type('') and type(Oprand2) == type(''): + if isinstance(Oprand1, type('')) and isinstance(Oprand2, type('')): if (Oprand1.startswith('L"') and not Oprand2.startswith('L"')) or \ (not Oprand1.startswith('L"') and Oprand2.startswith('L"')): raise BadExpression(ERR_STRING_CMP % (Oprand1, Operator, Oprand2)) - if 'in' in Operator and type(Oprand2) == type(''): + if 'in' in Operator and isinstance(Oprand2, type('')): Oprand2 = Oprand2.split() EvalStr = 'Oprand1 ' + Operator + ' Oprand2' @@ -248,7 +248,7 @@ class ValueExpression(object): def __init__(self, Expression, SymbolTable={}): self._NoProcess = False - if type(Expression) != type(''): + if not isinstance(Expression, type('')): self._Expr = Expression self._NoProcess = True return @@ -296,7 +296,7 @@ class ValueExpression(object): Token = self._GetToken() except BadExpression: pass - if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len: + if isinstance(Token, type('')) and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len: if len(Token) != len(self._Expr.replace(' ', '')): raise BadExpression return self._Expr @@ -306,7 +306,7 @@ class ValueExpression(object): Val = self._ConExpr() RealVal = Val - if type(Val) == type(''): + if isinstance(Val, type('')): if Val == 'L""': Val = False elif not Val: @@ -554,7 +554,7 @@ class ValueExpression(object): Ex.Pcd = self._Token raise Ex self._Token = ValueExpression(self._Symb[self._Token], self._Symb)(True, self._Depth+1) - if type(self._Token) != type(''): + if not isinstance(self._Token, type('')): self._LiteralToken = hex(self._Token) return @@ -657,7 +657,7 @@ class ValueExpression(object): if Ch == ')': TmpValue = self._Expr[Idx :self._Idx - 1] TmpValue = ValueExpression(TmpValue)(True) - TmpValue = '0x%x' % int(TmpValue) if type(TmpValue) != type('') else TmpValue + TmpValue = '0x%x' % int(TmpValue) if not isinstance(TmpValue, type('')) else TmpValue break self._Token, Size = ParseFieldValue(Prefix + '(' + TmpValue + ')') return self._Token @@ -750,9 +750,9 @@ class ValueExpressionEx(ValueExpression): except BadExpression: if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']: PcdValue = PcdValue.strip() - if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'): + if isinstance(PcdValue, type('')) and PcdValue.startswith('{') and PcdValue.endswith('}'): PcdValue = PcdValue[1:-1].split(',') - if type(PcdValue) == type([]): + if isinstance(PcdValue, type([])): TmpValue = 0 Size = 0 for Item in PcdValue: @@ -771,14 +771,14 @@ class ValueExpressionEx(ValueExpression): else: ItemValue = ParseFieldValue(Item)[0] - if type(ItemValue) == type(''): + if isinstance(ItemValue, type('')): ItemValue = int(ItemValue, 16) if ItemValue.startswith('0x') else int(ItemValue) TmpValue = (ItemValue << (Size * 8)) | TmpValue Size = Size + ItemSize else: TmpValue, Size = ParseFieldValue(PcdValue) - if type(TmpValue) == type(''): + if isinstance(TmpValue, type('')): TmpValue = int(TmpValue) else: PcdValue = '0x%0{}X'.format(Size) % (TmpValue) @@ -824,13 +824,13 @@ class ValueExpressionEx(ValueExpression): else: ListItem = PcdValue.split(',') - if type(ListItem) == type(0): + if isinstance(ListItem, type(0)): for Index in range(0, Size): ValueStr += '0x%02X' % (int(ListItem) & 255) ListItem >>= 8 ValueStr += ', ' PcdValue = '{' + ValueStr[:-2] + '}' - elif type(ListItem) == type(''): + elif isinstance(ListItem, type('')): if ListItem.startswith('{') and ListItem.endswith('}'): PcdValue = ListItem else: @@ -875,7 +875,7 @@ class ValueExpressionEx(ValueExpression): TmpValue = ValueExpressionEx(Item, ValueType, self._Symb)(True) else: TmpValue = ValueExpressionEx(Item, self.PcdType, self._Symb)(True) - Item = '0x%x' % TmpValue if type(TmpValue) != type('') else TmpValue + Item = '0x%x' % TmpValue if not isinstance(TmpValue, type('')) else TmpValue if ItemSize == 0: ItemValue, ItemSize = ParseFieldValue(Item) else: diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 10cb95559822..1a7418734cf8 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1508,9 +1508,9 @@ def ParseDevPathValue (Value): return '{' + out + '}', Size def ParseFieldValue (Value): - if type(Value) == type(0): + if isinstance(Value, type(0)): return Value, (Value.bit_length() + 7) / 8 - if type(Value) != type(''): + if not isinstance(Value, type('')): raise BadExpression('Type %s is %s' %(Value, type(Value))) Value = Value.strip() if Value.startswith('UINT8') and Value.endswith(')'): @@ -1834,8 +1834,7 @@ def CheckPcdDatum(Type, Value): Printset.add(TAB_PRINTCHAR_BS) Printset.add(TAB_PRINTCHAR_NUL) if not set(Value).issubset(Printset): - PrintList = list(Printset) - PrintList.sort() + PrintList = sorted(Printset) return False, "Invalid PCD string value of type [%s]; must be printable chars %s." % (Type, PrintList) elif Type == 'BOOLEAN': if Value not in ['TRUE', 'True', 'true', '0x1', '0x01', '1', 'FALSE', 'False', 'false', '0x0', '0x00', '0']: @@ -1997,7 +1996,7 @@ class PathClass(object): # @retval True The two PathClass are the same # def __eq__(self, Other): - if type(Other) == type(self): + if isinstance(Other, type(self)): return self.Path == Other.Path else: return self.Path == str(Other) @@ -2010,7 +2009,7 @@ class PathClass(object): # @retval -1 The first PathClass is less than the second PathClass # @retval 1 The first PathClass is Bigger than the second PathClass def __cmp__(self, Other): - if type(Other) == type(self): + if isinstance(Other, type(self)): OtherKey = Other.Path else: OtherKey = str(Other) @@ -2256,7 +2255,7 @@ class SkuClass(): return ["DEFAULT"] skulist = [sku] nextsku = sku - while 1: + while True: nextsku = self.GetNextSkuId(nextsku) skulist.append(nextsku) if nextsku == "DEFAULT": diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py index 496961554e87..1bf3adab1e1d 100644 --- a/BaseTools/Source/Python/Common/RangeExpression.py +++ b/BaseTools/Source/Python/Common/RangeExpression.py @@ -106,7 +106,7 @@ class XOROperatorObject(object): def __init__(self): pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) == type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr = "XOR ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId = str(uuid.uuid1()) @@ -120,7 +120,7 @@ class LEOperatorObject(object): def __init__(self): pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) == type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr = "LE ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 = str(uuid.uuid1()) @@ -132,7 +132,7 @@ class LTOperatorObject(object): def __init__(self): pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) == type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr = "LT ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 = str(uuid.uuid1()) @@ -145,7 +145,7 @@ class GEOperatorObject(object): def __init__(self): pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) == type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr = "GE ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 = str(uuid.uuid1()) @@ -158,7 +158,7 @@ class GTOperatorObject(object): def __init__(self): pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) == type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr = "GT ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 = str(uuid.uuid1()) @@ -171,7 +171,7 @@ class EQOperatorObject(object): def __init__(self): pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) == type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr = "EQ ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 = str(uuid.uuid1()) @@ -370,7 +370,7 @@ class RangeExpression(object): def __init__(self, Expression, PcdDataType, SymbolTable = {}): self._NoProcess = False - if type(Expression) != type(''): + if not isinstance(Expression, type('')): self._Expr = Expression self._NoProcess = True return @@ -591,7 +591,7 @@ class RangeExpression(object): Ex.Pcd = self._Token raise Ex self._Token = RangeExpression(self._Symb[self._Token], self._Symb)(True, self._Depth + 1) - if type(self._Token) != type(''): + if not isinstance(self._Token, type('')): self._LiteralToken = hex(self._Token) return diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Python/Common/String.py index 358e7b8d7c31..d2ec46d84eb8 100644 --- a/BaseTools/Source/Python/Common/String.py +++ b/BaseTools/Source/Python/Common/String.py @@ -246,7 +246,7 @@ def SplitModuleType(Key): def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False): NewList = [] for String in StringList: - if type(String) == type(''): + if isinstance(String, type('')): NewList.append(ReplaceMacro(String, MacroDefinitions, SelfReplacement)) else: NewList.append(String) @@ -782,7 +782,7 @@ def RemoveBlockComment(Lines): # Get String of a List # def GetStringOfList(List, Split=' '): - if type(List) != type([]): + if not isinstance(List, type([])): return List Str = '' for Item in List: diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py b/BaseTools/Source/Python/Common/TargetTxtClassObject.py index 3408cff8d75e..9c1e6b407356 100644 --- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py +++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py @@ -159,7 +159,7 @@ class TargetTxtClassObject(object): # @param key: The key of the item to be printed # def printList(Key, List): - if type(List) == type([]): + if isinstance(List, type([])): if len(List) > 0: if Key.find(TAB_SPLIT) != -1: print("\n" + Key) diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseTools/Source/Python/Common/ToolDefClassObject.py index 6dab179efc01..d3587b171192 100644 --- a/BaseTools/Source/Python/Common/ToolDefClassObject.py +++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py @@ -155,7 +155,7 @@ class ToolDefClassObject(object): if ErrorCode != 0: EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=IncFile) - if type(IncFileTmp) is PathClass: + if isinstance(IncFileTmp, PathClass): IncFile = IncFileTmp.Path else: IncFile = IncFileTmp diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py index d59697c64b68..96d906ae2b3a 100644 --- a/BaseTools/Source/Python/Common/VpdInfoFile.py +++ b/BaseTools/Source/Python/Common/VpdInfoFile.py @@ -128,8 +128,7 @@ class VpdInfoFile: "Invalid parameter FilePath: %s." % FilePath) Content = FILE_COMMENT_TEMPLATE - Pcds = self._VpdArray.keys() - Pcds.sort() + Pcds = sorted(self._VpdArray.keys()) for Pcd in Pcds: i = 0 PcdTokenCName = Pcd.TokenCName diff --git a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py b/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py index 145c7435cd12..605a1d847c61 100644 --- a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py @@ -69,7 +69,7 @@ def ParseMacro(Parser): self._ItemType = MODEL_META_DATA_DEFINE # DEFINE defined macros if Type == TAB_DSC_DEFINES_DEFINE: - if type(self) == DecParser: + if isinstance(self, DecParser): if MODEL_META_DATA_HEADER in self._SectionType: self._FileLocalMacros[Name] = Value else: @@ -84,7 +84,7 @@ def ParseMacro(Parser): SectionLocalMacros = self._SectionsMacroDict[SectionDictKey] SectionLocalMacros[Name] = Value # EDK_GLOBAL defined macros - elif type(self) != DscParser: + elif not isinstance(self, DscParser): EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used in .dsc file", ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) elif self._SectionType != MODEL_META_DATA_HEADER: @@ -216,7 +216,7 @@ class MetaFileParser(object): # DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)] # def __getitem__(self, DataInfo): - if type(DataInfo) != type(()): + if not isinstance(DataInfo, type(())): DataInfo = (DataInfo,) # Parse the file first, if necessary @@ -258,7 +258,7 @@ class MetaFileParser(object): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] = TokenList # Don't do macro replacement for dsc file at this point - if type(self) != DscParser: + if not isinstance(self, DscParser): Macros = self._Macros self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList] @@ -356,7 +356,7 @@ class MetaFileParser(object): if os.path.exists(UniFile): self._UniObj = UniParser(UniFile, IsExtraUni=False, IsModuleUni=False) - if type(self) == InfParser and self._Version < 0x00010005: + if isinstance(self, InfParser) and self._Version < 0x00010005: # EDK module allows using defines as macros self._FileLocalMacros[Name] = Value self._Defines[Name] = Value @@ -371,7 +371,7 @@ class MetaFileParser(object): self._ValueList[1] = TokenList2[1] # keys else: self._ValueList[1] = TokenList[0] - if len(TokenList) == 2 and type(self) != DscParser: # value + if len(TokenList) == 2 and not isinstance(self, DscParser): # value self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros) if self._ValueList[1].count('_') != 4: diff --git a/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py b/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py index eb76f4e6d54a..313fad602841 100644 --- a/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py +++ b/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py @@ -35,7 +35,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList): Element.appendChild(Doc.createTextNode(String)) for Item in NodeList: - if type(Item) == type([]): + if isinstance(Item, type([])): Key = Item[0] Value = Item[1] if Key != '' and Key != None and Value != '' and Value != None: diff --git a/BaseTools/Source/Python/Eot/Parser.py b/BaseTools/Source/Python/Eot/Parser.py index ab19e30b69aa..951fe7e3be2e 100644 --- a/BaseTools/Source/Python/Eot/Parser.py +++ b/BaseTools/Source/Python/Eot/Parser.py @@ -731,7 +731,7 @@ def GetParameter(Parameter, Index = 1): # @return: The name of parameter # def GetParameterName(Parameter): - if type(Parameter) == type('') and Parameter.startswith('&'): + if isinstance(Parameter, type('')) and Parameter.startswith('&'): return Parameter[1:].replace('{', '').replace('}', '').replace('\r', '').replace('\n', '').strip() else: return Parameter.strip() diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index 0aadbbd080b3..cb8dabbe038d 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -372,7 +372,7 @@ def CheckBuildOptionPcd(): for Arch in GenFdsGlobalVariable.ArchList: PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag) for i, pcd in enumerate(GlobalData.BuildOptionPcd): - if type(pcd) is tuple: + if isinstance(pcd, tuple): continue (pcdname, pcdvalue) = pcd.split('=') if not pcdvalue: @@ -840,7 +840,7 @@ class GenFds : if not Name: continue - Name = ' '.join(Name) if type(Name) == type([]) else Name + Name = ' '.join(Name) if isinstance(Name, type([])) else Name GuidXRefFile.write("%s %s\n" %(FileStatementGuid, Name)) # Append GUIDs, Protocols, and PPIs to the Xref file diff --git a/BaseTools/Source/Python/TargetTool/TargetTool.py b/BaseTools/Source/Python/TargetTool/TargetTool.py index fe74abb28901..2b6124dd4579 100644 --- a/BaseTools/Source/Python/TargetTool/TargetTool.py +++ b/BaseTools/Source/Python/TargetTool/TargetTool.py @@ -84,7 +84,7 @@ class TargetTool(): KeyList = self.TargetTxtDictionary.keys() errMsg = '' for Key in KeyList: - if type(self.TargetTxtDictionary[Key]) == type([]): + if isinstance(self.TargetTxtDictionary[Key], type([])): print("%-30s = %s" % (Key, ''.join(elem + ' ' for elem in self.TargetTxtDictionary[Key]))) elif self.TargetTxtDictionary[Key] == None: errMsg += " Missing %s configuration information, please use TargetTool to set value!" % Key + os.linesep diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py index d39c1827ba26..53d7b2b19b52 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py @@ -123,8 +123,7 @@ def GenPcd(Package, Content): if Pcd.GetSupModuleList(): Statement += GenDecTailComment(Pcd.GetSupModuleList()) - ArchList = Pcd.GetSupArchList() - ArchList.sort() + ArchList = sorted(Pcd.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ @@ -205,8 +204,7 @@ def GenGuidProtocolPpi(Package, Content): # if Guid.GetSupModuleList(): Statement += GenDecTailComment(Guid.GetSupModuleList()) - ArchList = Guid.GetSupArchList() - ArchList.sort() + ArchList = sorted(Guid.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ @@ -246,8 +244,7 @@ def GenGuidProtocolPpi(Package, Content): # if Protocol.GetSupModuleList(): Statement += GenDecTailComment(Protocol.GetSupModuleList()) - ArchList = Protocol.GetSupArchList() - ArchList.sort() + ArchList = sorted(Protocol.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ @@ -287,8 +284,7 @@ def GenGuidProtocolPpi(Package, Content): # if Ppi.GetSupModuleList(): Statement += GenDecTailComment(Ppi.GetSupModuleList()) - ArchList = Ppi.GetSupArchList() - ArchList.sort() + ArchList = sorted(Ppi.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ @@ -463,8 +459,7 @@ def PackageToDec(Package, DistHeader = None): if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) - ArchList = LibraryClass.GetSupArchList() - ArchList.sort() + ArchList = sorted(LibraryClass.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py index 4a9528b500f2..4dcdcff4f13a 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py @@ -494,8 +494,7 @@ def GenPackages(ModuleObject): Statement += RelaPath.replace('\\', '/') if FFE: Statement += '|' + FFE - ArchList = PackageDependency.GetSupArchList() - ArchList.sort() + ArchList = sorted(PackageDependency.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement] @@ -514,8 +513,7 @@ def GenSources(ModuleObject): SourceFile = Source.GetSourceFile() Family = Source.GetFamily() FeatureFlag = Source.GetFeatureFlag() - SupArchList = Source.GetSupArchList() - SupArchList.sort() + SupArchList = sorted(Source.GetSupArchList()) SortedArch = ' '.join(SupArchList) Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag) if SortedArch in NewSectionDict: @@ -723,8 +721,7 @@ def GenGuidSections(GuidObjList): # # merge duplicate items # - ArchList = Guid.GetSupArchList() - ArchList.sort() + ArchList = sorted(Guid.GetSupArchList()) SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in GuidDict: PreviousComment = GuidDict[Statement, SortedArch] @@ -783,8 +780,7 @@ def GenProtocolPPiSections(ObjList, IsProtocol): # # merge duplicate items # - ArchList = Object.GetSupArchList() - ArchList.sort() + ArchList = sorted(Object.GetSupArchList()) SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] @@ -858,8 +854,7 @@ def GenPcdSections(ModuleObject): # # Merge duplicate entries # - ArchList = Pcd.GetSupArchList() - ArchList.sort() + ArchList = sorted(Pcd.GetSupArchList()) SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] @@ -1026,8 +1021,7 @@ def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''): if CommentStr and not CommentStr.endswith('\n#\n'): CommentStr = CommentStr + '#\n' NewStateMent = CommentStr + Statement - SupArch = Obj.GetSupArchList() - SupArch.sort() + SupArch = sorted(Obj.GetSupArchList()) SortedArch = ' '.join(SupArch) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent] @@ -1105,8 +1099,7 @@ def GenBinaries(ModuleObject): FileName = ConvertPath(FileNameObj.GetFilename()) FileType = FileNameObj.GetFileType() FFE = FileNameObj.GetFeatureFlag() - ArchList = FileNameObj.GetSupArchList() - ArchList.sort() + ArchList = sorted(FileNameObj.GetSupArchList()) SortedArch = ' '.join(ArchList) Key = (FileName, FileType, FFE, SortedArch) if Key in BinariesDict: diff --git a/BaseTools/Source/Python/UPT/Library/Misc.py b/BaseTools/Source/Python/UPT/Library/Misc.py index 24e0a20daf87..936db991cdf5 100644 --- a/BaseTools/Source/Python/UPT/Library/Misc.py +++ b/BaseTools/Source/Python/UPT/Library/Misc.py @@ -515,7 +515,7 @@ class PathClass(object): # Check whether PathClass are the same # def __eq__(self, Other): - if type(Other) == type(self): + if isinstance(Other, type(self)): return self.Path == Other.Path else: return self.Path == str(Other) @@ -820,11 +820,11 @@ def ConvertArchList(ArchList): if not ArchList: return NewArchList - if type(ArchList) == list: + if isinstance(ArchList, list): for Arch in ArchList: Arch = Arch.upper() NewArchList.append(Arch) - elif type(ArchList) == str: + elif isinstance(ArchList, str): ArchList = ArchList.upper() NewArchList.append(ArchList) diff --git a/BaseTools/Source/Python/UPT/Library/ParserValidate.py b/BaseTools/Source/Python/UPT/Library/ParserValidate.py index 028cf9a54f84..5348073b56ba 100644 --- a/BaseTools/Source/Python/UPT/Library/ParserValidate.py +++ b/BaseTools/Source/Python/UPT/Library/ParserValidate.py @@ -341,7 +341,7 @@ def IsValidCFormatGuid(Guid): # # Index may out of bound # - if type(List[Index]) != type(1) or \ + if not isinstance(List[Index], type(1)) or \ len(Value) > List[Index] or len(Value) < 3: return False diff --git a/BaseTools/Source/Python/UPT/Library/String.py b/BaseTools/Source/Python/UPT/Library/String.py index de3035279f01..e6cab4650373 100644 --- a/BaseTools/Source/Python/UPT/Library/String.py +++ b/BaseTools/Source/Python/UPT/Library/String.py @@ -652,7 +652,7 @@ def ConvertToSqlString2(String): # @param Split: split character # def GetStringOfList(List, Split=' '): - if type(List) != type([]): + if not isinstance(List, type([])): return List Str = '' for Item in List: diff --git a/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py b/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py index fd02efb6bf04..05fe3b547326 100644 --- a/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py +++ b/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py @@ -40,7 +40,7 @@ def CreateXmlElement(Name, String, NodeList, AttributeList): Element.appendChild(Doc.createTextNode(String)) for Item in NodeList: - if type(Item) == type([]): + if isinstance(Item, type([])): Key = Item[0] Value = Item[1] if Key != '' and Key != None and Value != '' and Value != None: diff --git a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py index 1e0c79d6677d..bcc5d96f9153 100644 --- a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py +++ b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py @@ -410,8 +410,7 @@ class DecPomAlignment(PackageObject): # PackagePath = os.path.split(self.GetFullPath())[0] IncludePathList = \ - [os.path.normpath(Path) + sep for Path in IncludesDict.keys()] - IncludePathList.sort() + sorted([os.path.normpath(Path) + sep for Path in IncludesDict.keys()]) # # get a non-overlap set of include path, IncludePathList should be diff --git a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py index a15173285345..c0e4805a3f15 100644 --- a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py +++ b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py @@ -614,8 +614,7 @@ class InfPomAlignment(ModuleObject): SourceFile = Item.GetSourceFileName() Family = Item.GetFamily() FeatureFlag = Item.GetFeatureFlagExp() - SupArchList = ConvertArchList(Item.GetSupArchList()) - SupArchList.sort() + SupArchList = sorted(ConvertArchList(Item.GetSupArchList())) Source = SourceFileObject() Source.SetSourceFile(SourceFile) Source.SetFamily(Family) diff --git a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py index 042d4784c84c..9685799a0f0d 100644 --- a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py +++ b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py @@ -194,8 +194,7 @@ def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObj # can be used for the attribute. # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty. # - SupArchList = ConvertArchList(ItemObj.GetSupArchList()) - SupArchList.sort() + SupArchList = sorted(ConvertArchList(ItemObj.GetSupArchList())) if len(SupArchList) == 1 and SupArchList[0] == 'COMMON': if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'): SupArchList = OriSupArchList diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py index 0e1161c96f64..088e22ba098b 100644 --- a/BaseTools/Source/Python/Workspace/BuildClassObject.py +++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py @@ -168,7 +168,7 @@ class StructurePcd(PcdClassObject): self.validateranges = PcdObject.validateranges if PcdObject.validateranges else self.validateranges self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions - if type(PcdObject) is StructurePcd: + if isinstance(PcdObject, StructurePcd): self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index b08bdfbc4f4e..8551a0d8b7e7 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -868,13 +868,13 @@ class DscBuildData(PlatformBuildClassObject): for pcdname in Pcds: pcd = Pcds[pcdname] Pcds[pcdname].SkuInfoList = {"DEFAULT":pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku} - if type(pcd) is StructurePcd and pcd.SkuOverrideValues: + if isinstance(pcd, StructurePcd) and pcd.SkuOverrideValues: Pcds[pcdname].SkuOverrideValues = {"DEFAULT":pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku} else: for pcdname in Pcds: pcd = Pcds[pcdname] Pcds[pcdname].SkuInfoList = {skuid:pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku} - if type(pcd) is StructurePcd and pcd.SkuOverrideValues: + if isinstance(pcd, StructurePcd) and pcd.SkuOverrideValues: Pcds[pcdname].SkuOverrideValues = {skuid:pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku} return Pcds def CompleteHiiPcdsDefaultStores(self, Pcds): @@ -1234,7 +1234,7 @@ class DscBuildData(PlatformBuildClassObject): File=self.MetaFile, Line = StrPcdSet[str_pcd][0][5]) # Add the Structure PCD that only defined in DEC, don't have override in DSC file for Pcd in self.DecPcds: - if type (self._DecPcds[Pcd]) is StructurePcd: + if isinstance(self._DecPcds[Pcd], StructurePcd): if Pcd not in S_pcd_set: str_pcd_obj_str = StructurePcd() str_pcd_obj_str.copy(self._DecPcds[Pcd]) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 8ceedf5aec78..b96d027cb19e 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -75,10 +75,10 @@ def ParseMacro(Parser): # # First judge whether this DEFINE is in conditional directive statements or not. # - if type(self) == DscParser and self._InDirective > -1: + if isinstance(self, DscParser) and self._InDirective > -1: pass else: - if type(self) == DecParser: + if isinstance(self, DecParser): if MODEL_META_DATA_HEADER in self._SectionType: self._FileLocalMacros[Name] = Value else: @@ -89,7 +89,7 @@ def ParseMacro(Parser): self._ConstructSectionMacroDict(Name, Value) # EDK_GLOBAL defined macros - elif type(self) != DscParser: + elif not isinstance(self, DscParser): EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used in .dsc file", ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1) elif self._SectionType != MODEL_META_DATA_HEADER: @@ -230,7 +230,7 @@ class MetaFileParser(object): # DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)] # def __getitem__(self, DataInfo): - if type(DataInfo) != type(()): + if not isinstance(DataInfo, type(())): DataInfo = (DataInfo,) # Parse the file first, if necessary @@ -272,7 +272,7 @@ class MetaFileParser(object): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] = TokenList # Don't do macro replacement for dsc file at this point - if type(self) != DscParser: + if not isinstance(self, DscParser): Macros = self._Macros self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList] @@ -379,7 +379,7 @@ class MetaFileParser(object): EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version number", ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1) - if type(self) == InfParser and self._Version < 0x00010005: + if isinstance(self, InfParser) and self._Version < 0x00010005: # EDK module allows using defines as macros self._FileLocalMacros[Name] = Value self._Defines[Name] = Value @@ -395,7 +395,7 @@ class MetaFileParser(object): self._ValueList[1] = TokenList2[1] # keys else: self._ValueList[1] = TokenList[0] - if len(TokenList) == 2 and type(self) != DscParser: # value + if len(TokenList) == 2 and not isinstance(self, DscParser): # value self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros) if self._ValueList[1].count('_') != 4: @@ -424,7 +424,7 @@ class MetaFileParser(object): # DecParser SectionType is a list, will contain more than one item only in Pcd Section # As Pcd section macro usage is not alllowed, so here it is safe # - if type(self) == DecParser: + if isinstance(self, DecParser): SectionDictKey = self._SectionType[0], ScopeKey if SectionDictKey not in self._SectionsMacroDict: self._SectionsMacroDict[SectionDictKey] = {} @@ -441,7 +441,7 @@ class MetaFileParser(object): SpeSpeMacroDict = {} ActiveSectionType = self._SectionType - if type(self) == DecParser: + if isinstance(self, DecParser): ActiveSectionType = self._SectionType[0] for (SectionType, Scope) in self._SectionsMacroDict: diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py index aa357e4ed62b..10b480d619c5 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -1758,8 +1758,7 @@ class FdRegionReport(object): for Match in gOffsetGuidPattern.finditer(FvReport): Guid = Match.group(2).upper() OffsetInfo[Match.group(1)] = self._GuidsDb.get(Guid, Guid) - OffsetList = OffsetInfo.keys() - OffsetList.sort() + OffsetList = sorted(OffsetInfo.keys()) for Offset in OffsetList: FileWrite (File, "%s %s" % (Offset, OffsetInfo[Offset])) except IOError: diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py index 6fbaad4c0fb6..03983c34beae 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -303,7 +303,7 @@ def LaunchCommand(Command, WorkingDir): if EndOfProcedure != None: EndOfProcedure.set() if Proc == None: - if type(Command) != type(""): + if not isinstance(Command, type("")): Command = " ".join(Command) EdkLogger.error("build", COMMAND_FAILURE, "Failed to start command", ExtraData="%s [%s]" % (Command, WorkingDir)) @@ -314,7 +314,7 @@ def LaunchCommand(Command, WorkingDir): # check the return code of the program if Proc.returncode != 0: - if type(Command) != type(""): + if not isinstance(Command, type("")): Command = " ".join(Command) # print out the Response file and its content when make failure RespFile = os.path.join(WorkingDir, 'OUTPUT', 'respfilelist.txt') diff --git a/BaseTools/gcc/mingw-gcc-build.py b/BaseTools/gcc/mingw-gcc-build.py index 3bf524123d0f..6a805ce51885 100755 --- a/BaseTools/gcc/mingw-gcc-build.py +++ b/BaseTools/gcc/mingw-gcc-build.py @@ -258,9 +258,9 @@ class SourceFiles: replaceables = ('extract-dir', 'filename', 'url') for replaceItem in fdata: if replaceItem in replaceables: continue - if type(fdata[replaceItem]) != str: continue + if not isinstance(fdata[replaceItem], str): continue for replaceable in replaceables: - if type(fdata[replaceable]) != str: continue + if not isinstance(fdata[replaceable], str): continue if replaceable in fdata: fdata[replaceable] = \ fdata[replaceable].replace( -- 2.16.1