From nobody Mon Dec 23 18:12:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1516337069962445.67920652296493; Thu, 18 Jan 2018 20:44:29 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0B0F72232BE1E; Thu, 18 Jan 2018 20:38:48 -0800 (PST) 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 1FB8E2232BDEA for ; Thu, 18 Jan 2018 20:38:44 -0800 (PST) Received: from localhost.localdomain (unknown.telstraglobal.net [134.159.103.118]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Fri, 19 Jan 2018 05:44:04 +0100 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 From: Gary Lin To: edk2-devel@lists.01.org Date: Fri, 19 Jan 2018 12:43:15 +0800 Message-Id: <20180119044316.4713-15-glin@suse.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180119044316.4713-1-glin@suse.com> References: <20180119044316.4713-1-glin@suse.com> Subject: [edk2] [PATCH 14/15] 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Based on "futurize -f lib2to3.fixes.fix_idioms" * Change some type comparisons to isinstance() calls: type(x) =3D=3D T -> isinstance(x, T) type(x) is T -> isinstance(x, T) type(x) !=3D T -> not isinstance(x, T) type(x) is not T -> not isinstance(x, T) * Change "while 1:" into "while True:". * Change both v =3D list(EXPR) v.sort() foo(v) and the more general v =3D EXPR v.sort() foo(v) into v =3D 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 | 5 +-- 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, 101 insertions(+), 120 deletions(-) diff --git a/BaseTools/Scripts/MemoryProfileSymbolGen.py b/BaseTools/Script= s/MemoryProfileSymbolGen.py index c9158800668d..b98f6dccea08 100644 --- a/BaseTools/Scripts/MemoryProfileSymbolGen.py +++ b/BaseTools/Scripts/MemoryProfileSymbolGen.py @@ -263,7 +263,7 @@ def main(): return 1 =20 try: - while 1: + while True: line =3D file.readline() if not line: break diff --git a/BaseTools/Scripts/UpdateBuildVersions.py b/BaseTools/Scripts/U= pdateBuildVersions.py index cff2e2263a8a..5725be57562f 100755 --- a/BaseTools/Scripts/UpdateBuildVersions.py +++ b/BaseTools/Scripts/UpdateBuildVersions.py @@ -253,7 +253,7 @@ def GetSvnRevision(opts): StatusCmd =3D "svn st -v --depth infinity --non-interactive" contents =3D ShellCommandResults(StatusCmd, opts) os.chdir(Cwd) - if type(contents) is ListType: + if isinstance(contents, ListType): for line in contents: if line.startswith("M "): Modified =3D True @@ -263,7 +263,7 @@ def GetSvnRevision(opts): InfoCmd =3D "svn info %s" % SrcPath.replace("\\", "/").strip() Revision =3D 0 contents =3D ShellCommandResults(InfoCmd, opts) - if type(contents) is IntType: + if isinstance(contents, IntType): return 0, Modified for line in contents: line =3D line.strip() @@ -284,7 +284,7 @@ def CheckSvn(opts): VerCmd =3D "svn --version" contents =3D ShellCommandResults(VerCmd, opts) opts.silent =3D 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 e8914df7310c..8b91904a289a 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -405,7 +405,7 @@ class WorkspaceAutoGen(AutoGen): PGen =3D PlatformAutoGen(self, self.MetaFile, Target, Toolchai= n, Arch) if GlobalData.BuildOptionPcd: for i, pcd in enumerate(GlobalData.BuildOptionPcd): - if type(pcd) is tuple: + if isinstance(pcd, tuple): continue (pcdname, pcdvalue) =3D pcd.split('=3D') if not pcdvalue: @@ -1673,8 +1673,7 @@ class PlatformAutoGen(AutoGen): PcdNvStoreDfBuffer.SkuInfoList[skuname].DefaultVal= ue =3D vardump PcdNvStoreDfBuffer.MaxDatumSize =3D str(len(vardum= p.split(","))) =20 - PlatformPcds =3D self._PlatformPcds.keys() - PlatformPcds.sort() + PlatformPcds =3D 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/Sou= rce/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) =20 def __eq__(self, Other): - if type(Other) =3D=3D type(self): + if isinstance(Other, type(self)): return Other.Target.Path =3D=3D self.Target.Path else: return str(Other) =3D=3D 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=3DFalse): self.ModuleType =3D ModuleType self.Phase =3D gType2Phase[ModuleType] - if type(Expression) =3D=3D type([]): + if isinstance(Expression, type([])): self.ExpressionString =3D " ".join(Expression) self.TokenList =3D Expression else: diff --git a/BaseTools/Source/Python/Common/Dictionary.py b/BaseTools/Sourc= e/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) =3D=3D type([]): + if isinstance(List, type([])): if len(List) > 0: if Key.find(TAB_SPLIT) !=3D -1: print("\n" + Key) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index d7714e54d47e..a1b4e9ce4d73 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 =3D None): WrnExp =3D None =20 - if Operator not in ["in", "not in"] and (type(Oprand1) =3D=3D type= ('') or type(Oprand2) =3D=3D type('')): - if type(Oprand1) =3D=3D 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 =3D ParseFieldValue(Oprand1) else: Oprand1, Size =3D ParseFieldValue('"' + Oprand1 + '"') - if type(Oprand2) =3D=3D type(''): + if isinstance(Oprand2, type('')): if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or= Oprand2.startswith("L'") or Oprand2.startswith('UINT'): Oprand2, Size =3D ParseFieldValue(Oprand2) else: Oprand2, Size =3D ParseFieldValue('"' + Oprand2 + '"') - if type(Oprand1) =3D=3D type('') or type(Oprand2) =3D=3D type(= ''): + if isinstance(Oprand1, type('')) or isinstance(Oprand2, type('= ')): raise BadExpression(ERR_STRING_EXPR % Operator) if Operator in ['in', 'not in']: - if type(Oprand1) !=3D type(''): + if not isinstance(Oprand1, type('')): Oprand1 =3D IntToStr(Oprand1) - if type(Oprand2) !=3D type(''): + if not isinstance(Oprand2, type('')): Oprand2 =3D IntToStr(Oprand2) TypeDict =3D { type(0) : 0, @@ -185,18 +185,18 @@ class ValueExpression(object): =20 EvalStr =3D '' if Operator in ["!", "NOT", "not"]: - if type(Oprand1) =3D=3D type(''): + if isinstance(Oprand1, type('')): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr =3D 'not Oprand1' elif Operator in ["~"]: - if type(Oprand1) =3D=3D type(''): + if isinstance(Oprand1, type('')): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr =3D '~ Oprand1' else: if Operator in ["+", "-"] and (type(True) in [type(Oprand1), t= ype(Oprand2)]): # Boolean in '+'/'-' will be evaluated but raise warning WrnExp =3D WrnExpression(WRN_BOOL_EXPR) - elif type('') in [type(Oprand1), type(Oprand2)] and type(Opran= d1)!=3D type(Oprand2): + elif type('') in [type(Oprand1), type(Oprand2)] and not isinst= ance(Oprand1, type(Oprand2)): # =3D=3D between string and number/boolean will always ret= urn False, !=3D return True if Operator =3D=3D "=3D=3D": WrnExp =3D WrnExpression(WRN_EQCMP_STR_OTHERS) @@ -217,11 +217,11 @@ class ValueExpression(object): pass else: raise BadExpression(ERR_EXPR_TYPE) - if type(Oprand1) =3D=3D type('') and type(Oprand2) =3D=3D 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, Operato= r, Oprand2)) - if 'in' in Operator and type(Oprand2) =3D=3D type(''): + if 'in' in Operator and isinstance(Oprand2, type('')): Oprand2 =3D Oprand2.split() EvalStr =3D 'Oprand1 ' + Operator + ' Oprand2' =20 @@ -248,7 +248,7 @@ class ValueExpression(object): =20 def __init__(self, Expression, SymbolTable=3D{}): self._NoProcess =3D False - if type(Expression) !=3D type(''): + if not isinstance(Expression, type('')): self._Expr =3D Expression self._NoProcess =3D True return @@ -297,7 +297,7 @@ class ValueExpression(object): =20 try: Token =3D self._GetToken() - if type(Token) =3D=3D type('') and Token.startswith('{') a= nd Token.endswith('}') and self._Idx >=3D self._Len: + if isinstance(Token, type('')) and Token.startswith('{') a= nd Token.endswith('}') and self._Idx >=3D self._Len: return self._Expr except BadExpression: pass @@ -307,7 +307,7 @@ class ValueExpression(object): =20 Val =3D self._ConExpr() RealVal =3D Val - if type(Val) =3D=3D type(''): + if isinstance(Val, type('')): if Val =3D=3D 'L""': Val =3D False elif not Val: @@ -548,7 +548,7 @@ class ValueExpression(object): Ex.Pcd =3D self._Token raise Ex self._Token =3D ValueExpression(self._Symb[self._Token], self.= _Symb)(True, self._Depth+1) - if type(self._Token) !=3D type(''): + if not isinstance(self._Token, type('')): self._LiteralToken =3D hex(self._Token) return =20 @@ -652,7 +652,7 @@ class ValueExpression(object): if Ch =3D=3D ')': TmpValue =3D self._Expr[Idx :self._Idx - 1] TmpValue =3D ValueExpression(TmpValue)(True) - TmpValue =3D '0x%x' % int(TmpValue) if type(TmpValue) = !=3D type('') else TmpValue + TmpValue =3D '0x%x' % int(TmpValue) if not isinstance(= TmpValue, type('')) else TmpValue break self._Token, Size =3D ParseFieldValue(Prefix + '(' + TmpValue = + ')') return self._Token @@ -744,9 +744,9 @@ class ValueExpressionEx(ValueExpression): PcdValue =3D '0' if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEA= N']: PcdValue =3D PcdValue.strip() - if type(PcdValue) =3D=3D type('') and PcdValue.startswith('{')= and PcdValue.endswith('}'): + if isinstance(PcdValue, type('')) and PcdValue.startswith('{')= and PcdValue.endswith('}'): PcdValue =3D PcdValue[1:-1].split(',') - if type(PcdValue) =3D=3D type([]): + if isinstance(PcdValue, type([])): TmpValue =3D 0 Size =3D 0 for Item in PcdValue: @@ -765,14 +765,14 @@ class ValueExpressionEx(ValueExpression): else: ItemValue =3D ParseFieldValue(Item)[0] =20 - if type(ItemValue) =3D=3D type(''): + if isinstance(ItemValue, type('')): ItemValue =3D int(ItemValue, 16) if ItemValue.star= tswith('0x') else int(ItemValue) =20 TmpValue =3D (ItemValue << (Size * 8)) | TmpValue Size =3D Size + ItemSize else: TmpValue, Size =3D ParseFieldValue(PcdValue) - if type(TmpValue) =3D=3D type(''): + if isinstance(TmpValue, type('')): TmpValue =3D int(TmpValue) else: PcdValue =3D '0x%0{}X'.format(Size) % (TmpValue) @@ -818,13 +818,13 @@ class ValueExpressionEx(ValueExpression): else: ListItem =3D PcdValue.split(',') =20 - if type(ListItem) =3D=3D type(0): + if isinstance(ListItem, type(0)): for Index in range(0, Size): ValueStr +=3D '0x%02X' % (int(ListItem) & 255) ListItem >>=3D 8 ValueStr +=3D ', ' PcdValue =3D '{' + ValueStr[:-2] + '}' - elif type(ListItem) =3D=3D type(''): + elif isinstance(ListItem, type('')): if ListItem.startswith('{') and ListItem.endswith(= '}'): PcdValue =3D ListItem else: @@ -861,7 +861,7 @@ class ValueExpressionEx(ValueExpression): else: ItemSize =3D 0 TmpValue =3D ValueExpressionEx(Item, self.PcdT= ype, self._Symb)(True) - Item =3D '0x%x' % TmpValue if type(TmpValue) != =3D type('') else TmpValue + Item =3D '0x%x' % TmpValue if not isinstance(T= mpValue, type('')) else TmpValue if ItemSize =3D=3D 0: ItemValue, ItemSize =3D ParseFieldValue(It= em) else: diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index 7a7f3f80c65a..b3d31b07256c 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 =20 def ParseFieldValue (Value): - if type(Value) =3D=3D type(0): + if isinstance(Value, type(0)): return Value, (Value.bit_length() + 7) / 8 - if type(Value) !=3D type(''): + if not isinstance(Value, type('')): raise BadExpression('Type %s is %s' %(Value, type(Value))) Value =3D 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 =3D list(Printset) - PrintList.sort() + PrintList =3D sorted(Printset) return False, "Invalid PCD string value of type [%s]; must= be printable chars %s." % (Type, PrintList) elif Type =3D=3D 'BOOLEAN': if Value not in ['TRUE', 'True', 'true', '0x1', '0x01', '1', 'FALS= E', '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) =3D=3D type(self): + if isinstance(Other, type(self)): return self.Path =3D=3D Other.Path else: return self.Path =3D=3D 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) =3D=3D type(self): + if isinstance(Other, type(self)): OtherKey =3D Other.Path else: OtherKey =3D str(Other) @@ -2256,7 +2255,7 @@ class SkuClass(): return ["DEFAULT"] skulist =3D [sku] nextsku =3D sku - while 1: + while True: nextsku =3D self.GetNextSkuId(nextsku) skulist.append(nextsku) if nextsku =3D=3D "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): =20 pass def Calculate(self, Operand, DataType, SymbolTable):=20 - if type(Operand) =3D=3D type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr =3D "XOR ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId =3D str(uuid.uuid1()) @@ -120,7 +120,7 @@ class LEOperatorObject(object): def __init__(self): =20 pass def Calculate(self, Operand, DataType, SymbolTable):=20 - if type(Operand) =3D=3D type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr =3D "LE ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 =3D str(uuid.uuid1()) @@ -132,7 +132,7 @@ class LTOperatorObject(object): def __init__(self): =20 pass def Calculate(self, Operand, DataType, SymbolTable): - if type(Operand) =3D=3D type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr =3D "LT ..."=20 raise BadExpression(ERR_SNYTAX % Expr)=20 rangeId1 =3D str(uuid.uuid1()) @@ -145,7 +145,7 @@ class GEOperatorObject(object): def __init__(self): =20 pass def Calculate(self, Operand, DataType, SymbolTable):=20 - if type(Operand) =3D=3D type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr =3D "GE ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 =3D str(uuid.uuid1()) @@ -158,7 +158,7 @@ class GTOperatorObject(object): def __init__(self): =20 pass def Calculate(self, Operand, DataType, SymbolTable):=20 - if type(Operand) =3D=3D type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr =3D "GT ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 =3D str(uuid.uuid1()) @@ -171,7 +171,7 @@ class EQOperatorObject(object): def __init__(self): =20 pass def Calculate(self, Operand, DataType, SymbolTable):=20 - if type(Operand) =3D=3D type('') and not Operand.isalnum(): + if isinstance(Operand, type('')) and not Operand.isalnum(): Expr =3D "EQ ..." raise BadExpression(ERR_SNYTAX % Expr) rangeId1 =3D str(uuid.uuid1()) @@ -370,7 +370,7 @@ class RangeExpression(object): =20 def __init__(self, Expression, PcdDataType, SymbolTable =3D {}): self._NoProcess =3D False - if type(Expression) !=3D type(''): + if not isinstance(Expression, type('')): self._Expr =3D Expression self._NoProcess =3D True return @@ -591,7 +591,7 @@ class RangeExpression(object): Ex.Pcd =3D self._Token raise Ex self._Token =3D RangeExpression(self._Symb[self._Token], self.= _Symb)(True, self._Depth + 1) - if type(self._Token) !=3D type(''): + if not isinstance(self._Token, type('')): self._LiteralToken =3D hex(self._Token) return =20 diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Py= thon/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=3D{}, SelfReplacement=3DFal= se): NewList =3D [] for String in StringList: - if type(String) =3D=3D type(''): + if isinstance(String, type('')): NewList.append(ReplaceMacro(String, MacroDefinitions, SelfRepl= acement)) else: NewList.append(String) @@ -782,7 +782,7 @@ def RemoveBlockComment(Lines): # Get String of a List # def GetStringOfList(List, Split=3D' '): - if type(List) !=3D type([]): + if not isinstance(List, type([])): return List Str =3D '' for Item in List: diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py b/BaseT= ools/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) =3D=3D type([]): + if isinstance(List, type([])): if len(List) > 0: if Key.find(TAB_SPLIT) !=3D -1: print("\n" + Key) diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseToo= ls/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 !=3D 0: EdkLogger.error("tools_def.txt parser", FI= LE_NOT_FOUND, ExtraData=3DIncFile) =20 - if type(IncFileTmp) is PathClass: + if isinstance(IncFileTmp, PathClass): IncFile =3D IncFileTmp.Path else: IncFile =3D IncFileTmp diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Sour= ce/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) = =20 =20 Content =3D FILE_COMMENT_TEMPLATE - Pcds =3D self._VpdArray.keys() - Pcds.sort() + Pcds =3D sorted(self._VpdArray.keys()) for Pcd in Pcds: i =3D 0 PcdTokenCName =3D Pcd.TokenCName diff --git a/BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.p= y 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 =3D MODEL_META_DATA_DEFINE # DEFINE defined macros if Type =3D=3D TAB_DSC_DEFINES_DEFINE: - if type(self) =3D=3D DecParser: + if isinstance(self, DecParser): if MODEL_META_DATA_HEADER in self._SectionType: self._FileLocalMacros[Name] =3D Value else: @@ -84,7 +84,7 @@ def ParseMacro(Parser): SectionLocalMacros =3D self._SectionsMacroDict[SectionDict= Key] SectionLocalMacros[Name] =3D Value # EDK_GLOBAL defined macros - elif type(self) !=3D DscParser: + elif not isinstance(self, DscParser): EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only= be used in .dsc file", ExtraData=3Dself._CurrentLine, File=3Dself.Met= aFile, Line=3Dself._LineIndex+1) elif self._SectionType !=3D MODEL_META_DATA_HEADER: @@ -216,7 +216,7 @@ class MetaFileParser(object): # DataInfo =3D [data_type, scope1(arch), scope2(platform/moduletype)] # def __getitem__(self, DataInfo): - if type(DataInfo) !=3D type(()): + if not isinstance(DataInfo, type(())): DataInfo =3D (DataInfo,) =20 # Parse the file first, if necessary @@ -258,7 +258,7 @@ class MetaFileParser(object): TokenList =3D GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] =3D TokenList # Don't do macro replacement for dsc file at this point - if type(self) !=3D DscParser: + if not isinstance(self, DscParser): Macros =3D self._Macros self._ValueList =3D [ReplaceMacro(Value, Macros) for Value in = self._ValueList] =20 @@ -356,7 +356,7 @@ class MetaFileParser(object): if os.path.exists(UniFile): self._UniObj =3D UniParser(UniFile, IsExtraUni=3DFalse, Is= ModuleUni=3DFalse) =20 - if type(self) =3D=3D InfParser and self._Version < 0x00010005: + if isinstance(self, InfParser) and self._Version < 0x00010005: # EDK module allows using defines as macros self._FileLocalMacros[Name] =3D Value self._Defines[Name] =3D Value @@ -371,7 +371,7 @@ class MetaFileParser(object): self._ValueList[1] =3D TokenList2[1] # keys else: self._ValueList[1] =3D TokenList[0] - if len(TokenList) =3D=3D 2 and type(self) !=3D DscParser: # value + if len(TokenList) =3D=3D 2 and not isinstance(self, DscParser): # = value self._ValueList[2] =3D ReplaceMacro(TokenList[1], self._Macros) =20 if self._ValueList[1].count('_') !=3D 4: diff --git a/BaseTools/Source/Python/Ecc/Xml/XmlRoutines.py b/BaseTools/Sou= rce/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, AttributeLis= t): Element.appendChild(Doc.createTextNode(String)) =20 for Item in NodeList: - if type(Item) =3D=3D type([]): + if isinstance(Item, type([])): Key =3D Item[0] Value =3D Item[1] if Key !=3D '' and Key !=3D None and Value !=3D '' and Value != =3D None: diff --git a/BaseTools/Source/Python/Eot/Parser.py b/BaseTools/Source/Pytho= n/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 =3D 1): # @return: The name of parameter # def GetParameterName(Parameter): - if type(Parameter) =3D=3D 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/Py= thon/GenFds/GenFds.py index bc7ef6408509..161955bc70ae 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -374,7 +374,7 @@ def CheckBuildOptionPcd(): for Arch in GenFdsGlobalVariable.ArchList: PkgList =3D GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsG= lobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFds= GlobalVariable.ToolChainTag) for i, pcd in enumerate(GlobalData.BuildOptionPcd): - if type(pcd) is tuple: + if isinstance(pcd, tuple): continue (pcdname, pcdvalue) =3D pcd.split('=3D') if not pcdvalue: @@ -842,7 +842,7 @@ class GenFds : if not Name: continue =20 - Name =3D ' '.join(Name) if type(Name) =3D=3D type(= []) else Name + Name =3D ' '.join(Name) if isinstance(Name, type([= ])) else Name GuidXRefFile.write("%s %s\n" %(FileStatementGuid, = Name)) =20 # Append GUIDs, Protocols, and PPIs to the Xref file diff --git a/BaseTools/Source/Python/TargetTool/TargetTool.py b/BaseTools/S= ource/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 =3D self.TargetTxtDictionary.keys() errMsg =3D '' for Key in KeyList: - if type(self.TargetTxtDictionary[Key]) =3D=3D type([]): + if isinstance(self.TargetTxtDictionary[Key], type([])): print("%-30s =3D %s" % (Key, ''.join(elem + ' ' for elem i= n self.TargetTxtDictionary[Key]))) elif self.TargetTxtDictionary[Key] =3D=3D None: errMsg +=3D " Missing %s configuration information, pleas= e use TargetTool to set value!" % Key + os.linesep=20 diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py b/BaseTo= ols/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 +=3D GenDecTailComment(Pcd.GetSupModuleList()) =20 - ArchList =3D Pcd.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Pcd.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D \ @@ -205,8 +204,7 @@ def GenGuidProtocolPpi(Package, Content): # if Guid.GetSupModuleList(): Statement +=3D GenDecTailComment(Guid.GetSupModuleList()) =20 - ArchList =3D Guid.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Guid.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D \ @@ -246,8 +244,7 @@ def GenGuidProtocolPpi(Package, Content): # if Protocol.GetSupModuleList(): Statement +=3D GenDecTailComment(Protocol.GetSupModuleList()) - ArchList =3D Protocol.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Protocol.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D \ @@ -287,8 +284,7 @@ def GenGuidProtocolPpi(Package, Content): # if Ppi.GetSupModuleList(): Statement +=3D GenDecTailComment(Ppi.GetSupModuleList()) - ArchList =3D Ppi.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Ppi.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D \ @@ -463,8 +459,7 @@ def PackageToDec(Package, DistHeader =3D None): if LibraryClass.GetSupModuleList(): Statement +=3D \ GenDecTailComment(LibraryClass.GetSupModuleList()) - ArchList =3D LibraryClass.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(LibraryClass.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D \ diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTo= ols/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 +=3D RelaPath.replace('\\', '/') if FFE: Statement +=3D '|' + FFE - ArchList =3D PackageDependency.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(PackageDependency.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D NewSectionDict[SortedArch] + [S= tatement] @@ -514,8 +513,7 @@ def GenSources(ModuleObject): SourceFile =3D Source.GetSourceFile() Family =3D Source.GetFamily() FeatureFlag =3D Source.GetFeatureFlag() - SupArchList =3D Source.GetSupArchList() - SupArchList.sort() + SupArchList =3D sorted(Source.GetSupArchList()) SortedArch =3D ' '.join(SupArchList) Statement =3D GenSourceStatement(ConvertPath(SourceFile), Family, = FeatureFlag) if SortedArch in NewSectionDict: @@ -723,8 +721,7 @@ def GenGuidSections(GuidObjList): # # merge duplicate items # - ArchList =3D Guid.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Guid.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if (Statement, SortedArch) in GuidDict: PreviousComment =3D GuidDict[Statement, SortedArch] @@ -783,8 +780,7 @@ def GenProtocolPPiSections(ObjList, IsProtocol): # # merge duplicate items # - ArchList =3D Object.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Object.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment =3D Dict[Statement, SortedArch] @@ -858,8 +854,7 @@ def GenPcdSections(ModuleObject): # # Merge duplicate entries # - ArchList =3D Pcd.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(Pcd.GetSupArchList()) SortedArch =3D ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment =3D Dict[Statement, SortedArch] @@ -1026,8 +1021,7 @@ def GenSpecialSections(ObjectList, SectionName, UserE= xtensionsContent=3D''): if CommentStr and not CommentStr.endswith('\n#\n'): CommentStr =3D CommentStr + '#\n' NewStateMent =3D CommentStr + Statement - SupArch =3D Obj.GetSupArchList() - SupArch.sort() + SupArch =3D sorted(Obj.GetSupArchList()) SortedArch =3D ' '.join(SupArch) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] =3D NewSectionDict[SortedArch] + [N= ewStateMent] @@ -1105,8 +1099,7 @@ def GenBinaries(ModuleObject): FileName =3D ConvertPath(FileNameObj.GetFilename()) FileType =3D FileNameObj.GetFileType() FFE =3D FileNameObj.GetFeatureFlag() - ArchList =3D FileNameObj.GetSupArchList() - ArchList.sort() + ArchList =3D sorted(FileNameObj.GetSupArchList()) SortedArch =3D ' '.join(ArchList) Key =3D (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) =3D=3D type(self): + if isinstance(Other, type(self)): return self.Path =3D=3D Other.Path else: return self.Path =3D=3D str(Other) @@ -820,11 +820,11 @@ def ConvertArchList(ArchList): if not ArchList: return NewArchList =20 - if type(ArchList) =3D=3D list: + if isinstance(ArchList, list): for Arch in ArchList: Arch =3D Arch.upper() NewArchList.append(Arch) - elif type(ArchList) =3D=3D str: + elif isinstance(ArchList, str): ArchList =3D ArchList.upper() NewArchList.append(ArchList) =20 diff --git a/BaseTools/Source/Python/UPT/Library/ParserValidate.py b/BaseTo= ols/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]) !=3D type(1) or \ + if not isinstance(List[Index], type(1)) or \ len(Value) > List[Index] or len(Value) < 3: return False =20 diff --git a/BaseTools/Source/Python/UPT/Library/String.py b/BaseTools/Sour= ce/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=3D' '): - if type(List) !=3D type([]): + if not isinstance(List, type([])): return List Str =3D '' for Item in List: diff --git a/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py b/BaseT= ools/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, AttributeLis= t): Element.appendChild(Doc.createTextNode(String)) =20 for Item in NodeList: - if type(Item) =3D=3D type([]): + if isinstance(Item, type([])): Key =3D Item[0] Value =3D Item[1] if Key !=3D '' and Key !=3D None and Value !=3D '' and Value != =3D None: diff --git a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py b/Ba= seTools/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): #=20 PackagePath =3D os.path.split(self.GetFullPath())[0] IncludePathList =3D \ - [os.path.normpath(Path) + sep for Path in IncludesDict.keys()] - IncludePathList.sort() + sorted([os.path.normpath(Path) + sep for Path in IncludesDict.= keys()]) =20 # # get a non-overlap set of include path, IncludePathList should be=20 diff --git a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py b/Ba= seTools/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 =3D Item.GetSourceFileName() Family =3D Item.GetFamily() FeatureFlag =3D Item.GetFeatureFlagExp() - SupArchList =3D ConvertArchList(Item.GetSupArchList()) - SupArchList.sort() + SupArchList =3D sorted(ConvertArchList(Item.GetSupArchList= ())) Source =3D 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. # =20 - SupArchList =3D ConvertArchList(ItemObj.GetSupArchList()) - SupArchList.sort() + SupArchList =3D sorted(ConvertArchList(ItemObj.GetSupArchList())) if len(SupArchList) =3D=3D 1 and SupArchList[0] =3D=3D 'COMMON': if not (len(OriSupArchList) =3D=3D 1 or OriSupArchList[0] =3D= =3D 'COMMON'): SupArchList =3D OriSupArchList diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTo= ols/Source/Python/Workspace/BuildClassObject.py index e5f1f01556e5..ee70597bc9a3 100644 --- a/BaseTools/Source/Python/Workspace/BuildClassObject.py +++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py @@ -162,7 +162,7 @@ class StructurePcd(PcdClassObject): self.validateranges =3D PcdObject.validateranges if PcdObject.vali= dateranges else self.validateranges self.validlists =3D PcdObject.validlists if PcdObject.validlists e= lse self.validlists self.expressions =3D PcdObject.expressions if PcdObject.expression= s else self.expressions - if type(PcdObject) is StructurePcd: + if isinstance(PcdObject, StructurePcd): self.StructuredPcdIncludeFile =3D PcdObject.StructuredPcdInclu= deFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdInclude= File self.PackageDecs =3D PcdObject.PackageDecs if PcdObject.Packag= eDecs else self.PackageDecs self.DefaultValues =3D PcdObject.DefaultValues if PcdObject.De= faultValues else self.DefaultValues diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index 5e61110df330..15af0c54bbe0 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -862,13 +862,13 @@ class DscBuildData(PlatformBuildClassObject): for pcdname in Pcds: pcd =3D Pcds[pcdname] Pcds[pcdname].SkuInfoList =3D {"DEFAULT":pcd.SkuInfoList[s= kuid] 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 =3D {"DEFAULT":pcd.Sku= OverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in availa= ble_sku} else: for pcdname in Pcds: pcd =3D Pcds[pcdname] Pcds[pcdname].SkuInfoList =3D {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 =3D {skuid:pcd.SkuOver= rideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_= sku} return Pcds def CompleteHiiPcdsDefaultStores(self, Pcds): @@ -1021,7 +1021,7 @@ class DscBuildData(PlatformBuildClassObject): File=3Dself.MetaFile, Line =3D StrPcdSet[str_p= cd][0][5]) # Add the Structure PCD that only defined in DEC, don't have overr= ide 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 =3D StructurePcd() str_pcd_obj_str.copy(self._DecPcds[Pcd]) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/Source/Python/Workspace/MetaFileParser.py index c85e3fe08649..902ed1fe338a 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) =3D=3D DscParser and self._InDirective > -1: + if isinstance(self, DscParser) and self._InDirective > -1: pass else: - if type(self) =3D=3D DecParser: + if isinstance(self, DecParser): if MODEL_META_DATA_HEADER in self._SectionType: self._FileLocalMacros[Name] =3D Value else: @@ -89,7 +89,7 @@ def ParseMacro(Parser): self._ConstructSectionMacroDict(Name, Value) =20 # EDK_GLOBAL defined macros - elif type(self) !=3D DscParser: + elif not isinstance(self, DscParser): EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only= be used in .dsc file", ExtraData=3Dself._CurrentLine, File=3Dself.Met= aFile, Line=3Dself._LineIndex + 1) elif self._SectionType !=3D MODEL_META_DATA_HEADER: @@ -230,7 +230,7 @@ class MetaFileParser(object): # DataInfo =3D [data_type, scope1(arch), scope2(platform/moduletype)] # def __getitem__(self, DataInfo): - if type(DataInfo) !=3D type(()): + if not isinstance(DataInfo, type(())): DataInfo =3D (DataInfo,) =20 # Parse the file first, if necessary @@ -272,7 +272,7 @@ class MetaFileParser(object): TokenList =3D GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] =3D TokenList # Don't do macro replacement for dsc file at this point - if type(self) !=3D DscParser: + if not isinstance(self, DscParser): Macros =3D self._Macros self._ValueList =3D [ReplaceMacro(Value, Macros) for Value in = self._ValueList] =20 @@ -379,7 +379,7 @@ class MetaFileParser(object): EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version= number", ExtraData=3Dself._CurrentLine, File=3Dself= .MetaFile, Line=3Dself._LineIndex + 1) =20 - if type(self) =3D=3D InfParser and self._Version < 0x00010005: + if isinstance(self, InfParser) and self._Version < 0x00010005: # EDK module allows using defines as macros self._FileLocalMacros[Name] =3D Value self._Defines[Name] =3D Value @@ -395,7 +395,7 @@ class MetaFileParser(object): self._ValueList[1] =3D TokenList2[1] # keys else: self._ValueList[1] =3D TokenList[0] - if len(TokenList) =3D=3D 2 and type(self) !=3D DscParser: # value + if len(TokenList) =3D=3D 2 and not isinstance(self, DscParser): # = value self._ValueList[2] =3D ReplaceMacro(TokenList[1], self._Macros) =20 if self._ValueList[1].count('_') !=3D 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) =3D=3D DecParser: + if isinstance(self, DecParser): SectionDictKey =3D self._SectionType[0], ScopeKey if SectionDictKey not in self._SectionsMacroDict: self._SectionsMacroDict[SectionDictKey] =3D {} @@ -441,7 +441,7 @@ class MetaFileParser(object): SpeSpeMacroDict =3D {} =20 ActiveSectionType =3D self._SectionType - if type(self) =3D=3D DecParser: + if isinstance(self, DecParser): ActiveSectionType =3D self._SectionType[0] =20 for (SectionType, Scope) in self._SectionsMacroDict: diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Sourc= e/Python/build/BuildReport.py index 3db1719c7769..3352504d502e 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -1753,8 +1753,7 @@ class FdRegionReport(object): for Match in gOffsetGuidPattern.finditer(FvReport): Guid =3D Match.group(2).upper() OffsetInfo[Match.group(1)] =3D self._GuidsDb.get(Guid,= Guid) - OffsetList =3D OffsetInfo.keys() - OffsetList.sort() + OffsetList =3D 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/Pyth= on/build/build.py index c64e8f265a97..f77924137665 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 !=3D None: EndOfProcedure.set() if Proc =3D=3D None: - if type(Command) !=3D type(""): + if not isinstance(Command, type("")): Command =3D " ".join(Command) EdkLogger.error("build", COMMAND_FAILURE, "Failed to start com= mand", ExtraData=3D"%s [%s]" % (Command, WorkingDir)) =20 @@ -314,7 +314,7 @@ def LaunchCommand(Command, WorkingDir): =20 # check the return code of the program if Proc.returncode !=3D 0: - if type(Command) !=3D type(""): + if not isinstance(Command, type("")): Command =3D " ".join(Command) # print out the Response file and its content when make failure RespFile =3D os.path.join(WorkingDir, 'OUTPUT', 'respfilelist.txt') diff --git a/BaseTools/gcc/mingw-gcc-build.py b/BaseTools/gcc/mingw-gcc-bui= ld.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 =3D ('extract-dir', 'filename', 'url') for replaceItem in fdata: if replaceItem in replaceables: continue - if type(fdata[replaceItem]) !=3D str: continue + if not isinstance(fdata[replaceItem], str): continue for replaceable in replaceables: - if type(fdata[replaceable]) !=3D str: continue + if not isinstance(fdata[replaceable], str): continue if replaceable in fdata: fdata[replaceable] =3D \ fdata[replaceable].replace( --=20 2.15.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel