[gobject-introspection] [maintransformer] Add more warnings for element-type



commit 013937b79ce3467068352e6dd0179efaf2563ac7
Author: Johan Dahlin <johan gnome org>
Date:   Fri Sep 24 09:59:21 2010 -0300

    [maintransformer] Add more warnings for element-type

 giscanner/maintransformer.py |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index fcbf109..605b1d1 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -358,19 +358,42 @@ usage is void (*_gtk_reserved1)(void);"""
 
     def _apply_annotations_element_type(self, parent, node, options):
         element_type_opt = options.get(OPT_ELEMENT_TYPE)
-        element_type = element_type_opt.flat()
+        if element_type_opt is None:
+            message.warn(
+                'element-type annotation takes at least one option, '
+                'none given',
+                options.position)
+            return
+
         if isinstance(node.type, ast.List):
-            assert len(element_type) == 1
-            node.type.element_type = self._resolve(element_type[0],
+            if element_type_opt.length() != 1:
+                message.warn(
+                    'element-type annotation for a list must have exactly '
+                    'one option, not %d options' % (element_type_opt.length(), ),
+                    options.position)
+                return
+            node.type.element_type = self._resolve(element_type_opt.one(),
                                                    node.type, node, parent)
         elif isinstance(node.type, ast.Map):
-            assert len(element_type) == 2
+            if element_type_opt.length() != 2:
+                message.warn(
+                    'element-type annotation for a hash table must have exactly '
+                    'two options, not %d option(s)' % (element_type_opt.length(), ),
+                    options.position)
+                return
+            element_type = element_type_opt.flat()
             node.type.key_type = self._resolve(element_type[0],
                                                node.type, node, parent)
             node.type.value_type = self._resolve(element_type[1],
                                                  node.type, node, parent)
         elif isinstance(node.type, ast.Array):
-            node.type.element_type = self._resolve(element_type[0],
+            if element_type_opt.length() != 1:
+                message.warn(
+                    'element-type annotation for an array must have exactly '
+                    'one option, not %d options' % (element_type_opt.length(), ),
+                    options.position)
+                return
+            node.type.element_type = self._resolve(element_type_opt.one(),
                                                    node.type, node, parent)
         else:
             message.warn_node(parent,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]