[Mesa-dev] [PATCH 18/41] glapi: gl_XML.py: use python's iter() function rather than calling __iter__

Ian Romanick idr at freedesktop.org
Tue Apr 19 22:08:15 UTC 2016


This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 03/31/2016 05:04 PM, Dylan Baker wrote:
> Python has what are often referred to as "magic methods". __iter__,
> __str__, __add__, and countless more. All of these methods exist to be
> called by another function or by an operator. The __add__ method
> implements the + operator, for example.
> 
> There are times to call the magic methods directly, but usually that's
> in cases where an implementation needs to call it's parent's method.
> Instead it's best to use the function or operator that the magic method
> implements.
> 
> This makes the code cleaner, more idiomatic, and just a bit nicer to
> read.
> 
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> ---
>  src/mapi/glapi/gen/gl_XML.py | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
> index d273ff0..42fcc41 100644
> --- a/src/mapi/glapi/gen/gl_XML.py
> +++ b/src/mapi/glapi/gen/gl_XML.py
> @@ -734,9 +734,9 @@ class gl_function(gl_item):
>  
>      def parameterIterator(self, name=None):
>          if name is not None:
> -            return self.entry_point_parameters[name].__iter__()
> +            return iter(self.entry_point_parameters[name])
>          else:
> -            return self.parameters.__iter__()
> +            return iter(self.parameters)
>  
>      def get_parameter_string(self, entrypoint=None):
>          if entrypoint:
> @@ -935,7 +935,7 @@ class gl_api(object):
>                  for name in names:
>                      functions.append(lists[func_cat_type][key][name])
>  
> -        return functions.__iter__()
> +        return iter(functions)
>  
>      def functionIterateByOffset(self):
>          max_offset = -1
> @@ -953,7 +953,7 @@ class gl_api(object):
>              if temp[i]:
>                  list.append(temp[i])
>  
> -        return list.__iter__()
> +        return iter(list)
>  
>      def functionIterateAll(self):
>          return self.functions_by_name.itervalues()
> @@ -966,7 +966,7 @@ class gl_api(object):
>          for enum in keys:
>              list.append(self.enums_by_name[enum])
>  
> -        return list.__iter__()
> +        return iter(list)
>  
>      def categoryIterate(self):
>          """Iterate over categories.
> @@ -983,7 +983,7 @@ class gl_api(object):
>              for key in keys:
>                  list.append(self.categories[cat_type][key])
>  
> -        return list.__iter__()
> +        return iter(list)
>  
>      def get_category_for_name(self, name):
>          if name in self.category_dict:
> 



More information about the mesa-dev mailing list