[pygobject] docs: Fix array length argument skipping with preceding out arguments



commit f6a87935596a3b59c238a5572b288f34691b53d1
Author: Simon Feltman <sfeltman src gnome org>
Date:   Tue Jan 7 07:31:22 2014 -0800

    docs: Fix array length argument skipping with preceding out arguments
    
    Remove split_function_info_args and use a list of all arguments for
    generating skipped index lists. Determine argument skipping based on the
    full argument list in each in/inout and out/inout argument list buildouts.
    This fixes a problem where out arguments preceding array length arguments
    would still show array length arguments in the docstring. This was due to an
    index mismatch when using split lists instead of list of all arguments.

 gi/docstring.py         |   38 ++++++++++++--------------------------
 tests/test_docstring.py |   37 +++++++++++++++----------------------
 2 files changed, 27 insertions(+), 48 deletions(-)
---
diff --git a/gi/docstring.py b/gi/docstring.py
index 77332e8..a1b8a51 100644
--- a/gi/docstring.py
+++ b/gi/docstring.py
@@ -59,25 +59,6 @@ def generate_doc_string(info):
     return _generate_doc_string_func(info)
 
 
-def split_function_info_args(info):
-    """Split a functions args into a tuple of two lists.
-
-    Note that args marked as Direction.INOUT will be in both lists.
-
-    :Returns:
-        Tuple of (in_args, out_args)
-    """
-    in_args = []
-    out_args = []
-    for arg in info.get_arguments():
-        direction = arg.get_direction()
-        if direction in (Direction.IN, Direction.INOUT):
-            in_args.append(arg)
-        if direction in (Direction.OUT, Direction.INOUT):
-            out_args.append(arg)
-    return (in_args, out_args)
-
-
 _type_tag_to_py_type = {TypeTag.BOOLEAN: bool,
                         TypeTag.INT8: int,
                         TypeTag.UINT8: int,
@@ -122,7 +103,6 @@ def _get_pytype_hint(gi_type):
 
 
 def _generate_callable_info_doc(info):
-    in_args, out_args = split_function_info_args(info)
     in_args_strs = []
     if isinstance(info, VFuncInfo):
         in_args_strs = ['self']
@@ -130,19 +110,22 @@ def _generate_callable_info_doc(info):
         if info.is_method():
             in_args_strs = ['self']
 
+    args = info.get_arguments()
     hint_blacklist = ('void',)
 
-    # Build a lists of indices prior to adding the docs because
-    # because it is possible the index retrieved comes before in
-    # argument being used.
+    # Build lists of indices prior to adding the docs because it is possible
+    # the index retrieved comes before input arguments being used.
     ignore_indices = set()
     user_data_indices = set()
-    for arg in in_args:
+    for arg in args:
         ignore_indices.add(arg.get_destroy())
         ignore_indices.add(arg.get_type().get_array_length())
         user_data_indices.add(arg.get_closure())
 
-    for i, arg in enumerate(in_args):
+    # Build input argument strings
+    for i, arg in enumerate(args):
+        if arg.get_direction() == Direction.OUT:
+            continue  # skip exclusively output args
         if i in ignore_indices:
             continue
         argstr = arg.get_name()
@@ -157,6 +140,7 @@ def _generate_callable_info_doc(info):
         in_args_strs.append(argstr)
     in_args_str = ', '.join(in_args_strs)
 
+    # Build return + output argument strings
     out_args_strs = []
     return_hint = _get_pytype_hint(info.get_return_type())
     if not info.skip_return and return_hint and return_hint not in hint_blacklist:
@@ -164,7 +148,9 @@ def _generate_callable_info_doc(info):
             argstr += ' or None'
         out_args_strs.append(return_hint)
 
-    for i, arg in enumerate(out_args):
+    for i, arg in enumerate(args):
+        if arg.get_direction() == Direction.IN:
+            continue  # skip exclusively input args
         if i in ignore_indices:
             continue
         argstr = arg.get_name()
diff --git a/tests/test_docstring.py b/tests/test_docstring.py
index e956f7d..a46d2e6 100644
--- a/tests/test_docstring.py
+++ b/tests/test_docstring.py
@@ -1,7 +1,6 @@
 import unittest
 
 import gi.docstring
-from gi.docstring import _get_pytype_hint
 from gi.repository import GIMarshallingTests
 from gi.repository import Gio
 
@@ -10,6 +9,7 @@ try:
     cairo = cairo
     has_cairo = True
     from gi.repository import Regress
+    from gi.repository import Gtk
 except ImportError:
     has_cairo = False
 
@@ -30,27 +30,6 @@ class Test(unittest.TestCase):
         self.assertEqual(gi.docstring.get_doc_string_generator(),
                          old_func)
 
-    def test_split_args_multi_out(self):
-        in_args, out_args = gi.docstring.split_function_info_args(GIMarshallingTests.int_out_out)
-        self.assertEqual(len(in_args), 0)
-        self.assertEqual(len(out_args), 2)
-        self.assertEqual(_get_pytype_hint(out_args[0].get_type()), 'int')
-        self.assertEqual(_get_pytype_hint(out_args[1].get_type()), 'int')
-
-    def test_split_args_inout(self):
-        in_args, out_args = gi.docstring.split_function_info_args(GIMarshallingTests.long_inout_max_min)
-        self.assertEqual(len(in_args), 1)
-        self.assertEqual(len(out_args), 1)
-        self.assertEqual(in_args[0].get_name(), out_args[0].get_name())
-        self.assertEqual(_get_pytype_hint(in_args[0].get_type()),
-                         _get_pytype_hint(out_args[0].get_type()))
-
-    def test_split_args_none(self):
-        obj = GIMarshallingTests.Object(int=33)
-        in_args, out_args = gi.docstring.split_function_info_args(obj.none_inout)
-        self.assertEqual(len(in_args), 1)
-        self.assertEqual(len(out_args), 1)
-
     def test_final_signature_with_full_inout(self):
         self.assertEqual(GIMarshallingTests.Object.full_inout.__doc__,
                          'full_inout(object:GIMarshallingTests.Object) -> object:GIMarshallingTests.Object')
@@ -91,3 +70,17 @@ class Test(unittest.TestCase):
     def test_private_struct_constructors(self):
         doc = Regress.TestBoxedPrivate.__doc__
         self.assertTrue('TestBoxedPrivate()' not in doc)
+
+    def test_array_inout_etc(self):
+        self.assertEqual(GIMarshallingTests.array_inout_etc.__doc__,
+                         'array_inout_etc(first:int, ints:list, last:int) -> ints:list, sum:int')
+
+    def test_array_out_etc(self):
+        self.assertEqual(GIMarshallingTests.array_out_etc.__doc__,
+                         'array_out_etc(first:int, last:int) -> ints:list, sum:int')
+
+    @unittest.skipUnless(has_cairo, 'built without cairo support')
+    def test_shared_array_length_with_prior_out_arg(self):
+        # Test the 'iter' out argument does not effect length argument skipping.
+        self.assertEqual(Gtk.ListStore.insert_with_valuesv.__doc__,
+                         'insert_with_valuesv(self, position:int, columns:list, values:list) -> 
iter:Gtk.TreeIter')


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