[Mesa-dev] [PATCH 04/26] python: Better check for keys in dicts
Eric Engestrom
eric.engestrom at intel.com
Thu Jul 5 14:00:55 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>
Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>
> ---
> 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(-)
>
> diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py
> index e1aa1b3e61..bbcecd6023 100644
> --- a/src/mapi/glapi/gen/glX_XML.py
> +++ b/src/mapi/glapi/gen/glX_XML.py
> @@ -64,7 +64,7 @@ class glx_enum(gl_XML.gl_enum):
> else:
> mode = 1
>
> - if not self.functions.has_key(n):
> + if n not in self.functions:
> self.functions[ n ] = [c, mode]
>
> return
> diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py
> index f199e9a0a1..7ab1eb4a70 100644
> --- a/src/mapi/glapi/gen/glX_proto_send.py
> +++ b/src/mapi/glapi/gen/glX_proto_send.py
> @@ -842,7 +842,7 @@ generic_%u_byte( GLint rop, const void * ptr )
>
>
> def printPixelFunction(self, f):
> - if self.pixel_stubs.has_key( f.name ):
> + if f.name in self.pixel_stubs:
> # Normally gl_function::get_parameter_string could be
> # used. However, this call needs to have the missing
> # dimensions (e.g., a fake height value for
> diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py
> index 284ee70e61..18a6f2e502 100644
> --- a/src/mapi/glapi/gen/glX_proto_size.py
> +++ b/src/mapi/glapi/gen/glX_proto_size.py
> @@ -71,7 +71,7 @@ class glx_enum_function(object):
> for enum_name in enum_dict:
> e = enum_dict[ enum_name ]
>
> - if e.functions.has_key( match_name ):
> + if match_name in e.functions:
> [count, mode] = e.functions[ match_name ]
>
> if mode_set and mode != self.mode:
> @@ -79,11 +79,11 @@ class glx_enum_function(object):
>
> self.mode = mode
>
> - if self.enums.has_key( e.value ):
> + if e.value in self.enums:
> if e.name not in self.enums[ e.value ]:
> self.enums[ e.value ].append( e )
> else:
> - if not self.count.has_key( count ):
> + if count not in self.count:
> self.count[ count ] = []
>
> self.enums[ e.value ] = [ e ]
> @@ -131,7 +131,7 @@ class glx_enum_function(object):
> for a in self.enums:
> count += 1
>
> - if self.count.has_key(-1):
> + if -1 in self.count:
> return 0
>
> # Determine if there is some mask M, such that M = (2^N) - 1,
> @@ -356,7 +356,7 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
>
> if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
> sig = ef.signature()
> - if enum_sigs.has_key( sig ):
> + if sig in enum_sigs:
> aliases.append( [func.name, enum_sigs[ sig ]] )
> else:
> enum_sigs[ sig ] = func.name
> @@ -477,10 +477,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
>
> sig = ef.signature()
>
> - if not enum_functions.has_key(func.name):
> + if func.name not in enum_functions:
> enum_functions[ func.name ] = sig
>
> - if not enum_sigs.has_key( sig ):
> + if sig not in enum_sigs:
> enum_sigs[ sig ] = ef
>
>
> @@ -496,7 +496,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
> if func.server_handcode: continue
> if not func.has_variable_size_request(): continue
>
> - if enum_functions.has_key(func.name):
> + if func.name in enum_functions:
> sig = enum_functions[func.name]
> ef = enum_sigs[ sig ]
>
> @@ -621,7 +621,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
> # already be emitted, don't emit this function. Instead, add
> # it to the list of function aliases.
>
> - if self.counter_sigs.has_key(sig):
> + if sig in self.counter_sigs:
> n = self.counter_sigs[sig];
> alias = [f.name, n]
> else:
> diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
> index 330ca0e5a6..52e2cab6b9 100644
> --- a/src/mapi/glapi/gen/gl_XML.py
> +++ b/src/mapi/glapi/gen/gl_XML.py
> @@ -943,7 +943,7 @@ class gl_api(object):
> temp_name = child.get( "name" )
> self.category_dict[ temp_name ] = [cat_name, cat_number]
>
> - if self.functions_by_name.has_key( func_name ):
> + if func_name in self.functions_by_name:
> func = self.functions_by_name[ func_name ]
> func.process_element( child )
> else:
> @@ -980,7 +980,7 @@ class gl_api(object):
> if (cat == None) or (cat == cat_name):
> [func_cat_type, key] = classify_category(cat_name, cat_number)
>
> - if not lists[func_cat_type].has_key(key):
> + if key not in lists[func_cat_type]:
> lists[func_cat_type][key] = {}
>
> lists[func_cat_type][key][func.name] = func
> @@ -1057,7 +1057,7 @@ class gl_api(object):
>
>
> def get_category_for_name( self, name ):
> - if self.category_dict.has_key(name):
> + if name in self.category_dict:
> return self.category_dict[name]
> else:
> return ["<unknown category>", None]
> diff --git a/src/mapi/glapi/gen/gl_procs.py b/src/mapi/glapi/gen/gl_procs.py
> index a7bc909ce2..5718f42ab6 100644
> --- a/src/mapi/glapi/gen/gl_procs.py
> +++ b/src/mapi/glapi/gen/gl_procs.py
> @@ -135,7 +135,7 @@ typedef struct {
> for n in func.entry_points:
> cat, num = api.get_category_for_name(n)
> if (cat.startswith("es") or cat.startswith("GL_OES")):
> - if not categories.has_key(cat):
> + if cat not in categories:
> categories[cat] = []
> proto = 'GLAPI %s GLAPIENTRY %s(%s);' \
> % (func.return_type, "gl" + n, func.get_parameter_string(n))
> 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 = []
> @@ -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
>
> diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
> index 8336e0f952..886c1854f3 100644
> --- a/src/util/xmlpool/gen_xmlpool.py
> +++ b/src/util/xmlpool/gen_xmlpool.py
> @@ -42,7 +42,7 @@ def escapeCString (s):
> # open quote
> q = u'\u201d'
> r = r + q
> - elif escapeSeqs.has_key(s[i]):
> + elif s[i] in escapeSeqs:
> r = r + escapeSeqs[s[i]]
> else:
> r = r + s[i]
> @@ -90,7 +90,7 @@ def expandCString (s):
> escape = False
> r = r + chr(num)
> else:
> - if escapeSeqs.has_key(s[i]):
> + if s[i] in escapeSeqs:
> r = r + escapeSeqs[s[i]]
> escape = False
> elif s[i] >= '0' and s[i] <= '7':
> --
> 2.17.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list