[Mesa-dev] [PATCH 04/26] python: Better check for keys in dicts
Eric Engestrom
eric.engestrom at intel.com
Thu Jul 5 14:08:05 UTC 2018
On Thursday, 2018-07-05 15:17:35 +0200, Mathieu Bridon wrote:
> 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 <bochecha at daitauha.fr>
> ---
> src/mapi/glapi/gen/glX_XML.py | 2 +-
> src/mapi/glapi/gen/glX_proto_send.py | 2 +-
> src/mapi/glapi/gen/glX_proto_size.py | 18 +++++++++---------
> src/mapi/glapi/gen/gl_XML.py | 6 +++---
> src/mapi/glapi/gen/gl_procs.py | 2 +-
> src/mapi/mapi_abi.py | 10 ++++------
> src/util/xmlpool/gen_xmlpool.py | 4 ++--
> 7 files changed, 21 insertions(+), 23 deletions(-)
>
[snip]
> diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py
> index 0a49c06ff2..826721479d 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 = []
I guess the two hunks below actually belong in path 7 :)
> @@ -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
>
[snip]
More information about the mesa-dev
mailing list