[libxcb,10/18] c_client.py: use pattern matching with enumerate()

Submitted by Ran Benita on Oct. 12, 2014, 6:58 p.m.

Details

Message ID 1413140300-20075-11-git-send-email-ran234@gmail.com
State Superseded
Headers show

Not browsing as part of any series.

Commit Message

Ran Benita Oct. 12, 2014, 6:58 p.m.
Signed-off-by: Ran Benita <ran234@gmail.com>
---
 src/c_client.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/c_client.py b/src/c_client.py
index 0488ea5..4c19722 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -483,8 +483,7 @@  def _c_helper_resolve_field_names (prefix):
     all_fields = {}
     tmp_prefix = []
     # look for fields in the remaining containers
-    for idx, p in enumerate(prefix):
-        name, sep, obj = p
+    for (idx, (name, sep, obj)) in enumerate(prefix):
         if ''==sep:
             # sep can be preset in prefix, if not, make a sensible guess
             sep = '.' if (obj.is_switch or obj.is_case_or_bitcase) else '->'
@@ -833,7 +832,7 @@  def _c_serialize_helper_fields_fixed_size(context, self, field,
     if not self.is_case_or_bitcase:
         code_lines.append('%s    /* %s.%s */' % (space, self.c_type, field.c_field_name))
     else:
-        scoped_name = [p[2].c_type if idx==0 else p[0] for idx, p in enumerate(prefix)]
+        scoped_name = [obj.c_type if idx==0 else name for idx, (name, sep, obj) in enumerate(prefix)]
         typename = ".".join(scoped_name)
         code_lines.append('%s    /* %s.%s */' % (space, typename, field.c_field_name))
 
@@ -1965,7 +1964,7 @@  def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_f
         _c('    void *xcb_aux = 0;')
 
 
-    for idx, f in enumerate(serial_fields):
+    for idx, _ in enumerate(serial_fields):
         if aux:
             _c('    void *xcb_aux%d = 0;' % (idx))
     if list_with_var_size_elems:

Comments

Le 12/10/2014 20:58, Ran Benita a écrit :
> @@ -483,8 +483,7 @@ def _c_helper_resolve_field_names (prefix):
>      all_fields = {}
>      tmp_prefix = []
>      # look for fields in the remaining containers
> -    for idx, p in enumerate(prefix):
> -        name, sep, obj = p
> +    for (idx, (name, sep, obj)) in enumerate(prefix):

The outer parenthesis can be dropped.

> @@ -833,7 +832,7 @@ def _c_serialize_helper_fields_fixed_size(context, self, field,
>      if not self.is_case_or_bitcase:
>          code_lines.append('%s    /* %s.%s */' % (space, self.c_type, field.c_field_name))
>      else:
> -        scoped_name = [p[2].c_type if idx==0 else p[0] for idx, p in enumerate(prefix)]
> +        scoped_name = [obj.c_type if idx==0 else name for idx, (name, sep, obj) in enumerate(prefix)]

sep is unused, use _ instead (just like you did in the following chunk).

Patch looks otherwise good.

Rémi