From 1d209275c29886bac218d77135f61ae52464a1be Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Thu, 5 Jul 2018 15:17:35 +0200 Subject: python: Better check for keys in dicts Python 3 lost the dict.has_key() method. Instead it requires using the "in" operator. This is also compatible with Python 2. Signed-off-by: Mathieu Bridon Reviewed-by: Eric Engestrom Reviewed-by: Dylan Baker Reviewed-by: Ian Romanick --- src/mapi/mapi_abi.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/mapi/mapi_abi.py') diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index 0a49c06ff2c..826721479d5 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -168,7 +168,7 @@ def abi_parse_xml(xml): else: attrs['handcode'] = None - if entry_dict.has_key(name): + if name in entry_dict: raise Exception('%s is duplicated' % (name)) cols = [] @@ -180,8 +180,7 @@ def abi_parse_xml(xml): ent = ABIEntry(cols, attrs, func) entry_dict[ent.name] = ent - entries = entry_dict.values() - entries.sort() + entries = sorted(entry_dict.values()) return entries @@ -246,12 +245,11 @@ def abi_parse(filename): raise Exception('invalid slot in %s' % (line)) ent = ABIEntry(cols, attrs) - if entry_dict.has_key(ent.name): + if ent.name in entry_dict: raise Exception('%s is duplicated' % (ent.name)) entry_dict[ent.name] = ent - entries = entry_dict.values() - entries.sort() + entries = sorted(entry_dict.values()) return entries -- cgit v1.2.3