summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Common/Misc.py
diff options
context:
space:
mode:
authorGary Lin <glin@suse.com>2018-06-25 18:31:35 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-06-27 16:33:27 +0800
commit0d1f5b2b5dc3c1cf381be0a1ec8f960dc6029a93 (patch)
tree370c6121707d6141988e1795f061e93abc112cbb /BaseTools/Source/Python/Common/Misc.py
parent2617a73c3628473bacea887d885bdd1e7808ccc6 (diff)
downloadedk2-0d1f5b2b5dc3c1cf381be0a1ec8f960dc6029a93.tar.gz
edk2-0d1f5b2b5dc3c1cf381be0a1ec8f960dc6029a93.tar.bz2
edk2-0d1f5b2b5dc3c1cf381be0a1ec8f960dc6029a93.zip
BaseTools: Fix old python2 idioms
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 <yonghong.zhu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Gary Lin <glin@suse.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common/Misc.py')
-rw-r--r--BaseTools/Source/Python/Common/Misc.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index fd53b6b046..55e3c6f228 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1291,9 +1291,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(TAB_UINT8) and Value.endswith(')'):
@@ -1584,8 +1584,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']:
@@ -1747,7 +1746,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)
@@ -1760,7 +1759,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)
@@ -2010,7 +2009,7 @@ class SkuClass():
return ["DEFAULT"]
skulist = [sku]
nextsku = sku
- while 1:
+ while True:
nextsku = self.GetNextSkuId(nextsku)
skulist.append(nextsku)
if nextsku == "DEFAULT":