[gobject-introspection/list-model-element-type: 4/4] Generate appropriate docs for ListModel with element-type



commit 9350477102f5f9724979a7bc5c2010f7b756e3fb
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Feb 21 13:37:58 2020 +0000

    Generate appropriate docs for ListModel with element-type
    
    We need to special case the ListModel container type in the
    documentation writer so that we don't fall back into array/list
    automatic conversion in the code snippets.

 giscanner/docwriter.py                                 | 18 +++++++++++++-----
 .../Regress.test_list_model_object.page                |  4 ++--
 .../Regress.test_list_model_object.page                |  4 ++--
 3 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index 786da80d..e4a8f7c5 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -793,7 +793,11 @@ class DocFormatterPython(DocFormatterIntrospectableBase):
         return fundamental_types.get(name, name)
 
     def format_type(self, type_, link=False):
-        if isinstance(type_, (ast.List, ast.Array)):
+        if isinstance(type_, ast.List):
+            if type_.name == 'Gio.ListModel':
+                return 'Gio.ListModel(item_type=' + self.format_type(type_.element_type) + ')'
+            return '[' + self.format_type(type_.element_type) + ']'
+        elif isinstance(type_, ast.Array):
             return '[' + self.format_type(type_.element_type) + ']'
         elif isinstance(type_, ast.Map):
             return '{%s: %s}' % (self.format_type(type_.key_type),
@@ -930,10 +934,14 @@ class DocFormatterGjs(DocFormatterIntrospectableBase):
         return fundamental_types.get(name, name)
 
     def format_type(self, type_, link=False):
-        if isinstance(type_, ast.Array) and \
-           type_.element_type.target_fundamental in ('gint8', 'guint8'):
-            return 'ByteArray'
-        elif isinstance(type_, (ast.List, ast.Array)):
+        if isinstance(type_, ast.Array):
+            if type_.element_type.target_fundamental in ('gint8', 'guint8'):
+                return 'ByteArray'
+            else:
+                return 'Array(' + self.format_type(type_.element_type, link) + ')'
+        elif isinstance(type_, ast.List):
+            if type_.name == 'Gio.ListModel':
+                return 'Gio.ListModel({item_type: ' + self.format_type(type_.element_type) + '})'
             return 'Array(' + self.format_type(type_.element_type, link) + ')'
         elif isinstance(type_, ast.Map):
             return '{%s: %s}' % (self.format_type(type_.key_type, link),
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_list_model_object.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_list_model_object.page
index a9dd90d7..618ca7e3 100644
--- a/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_list_model_object.page
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_list_model_object.page
@@ -9,14 +9,14 @@
     <link xref="index" group="function" type="guide"/>
     <api:function>
       <api:returns>
-        <api:type>Array(Regress.TestObj)</api:type>
+        <api:type>Gio.ListModel({item_type: Regress.TestObj})</api:type>
       </api:returns>
       <api:name>regress_test_list_model_object</api:name>
     </api:function>
   </info>
   <title>Regress.test_list_model_object</title>
   <synopsis><code mime="text/x-gjs">
-function test_list_model_object(): Array(<link xref="Regress.TestObj">Regress.TestObj</link>) {
+function test_list_model_object(): Gio.ListModel({item_type: Regress.TestObj}) {
     // Gjs wrapper for regress_test_list_model_object()
 }
   </code></synopsis>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.test_list_model_object.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.test_list_model_object.page
index a4382c9d..d9dca201 100644
--- a/tests/scanner/Regress-1.0-Python-expected/Regress.test_list_model_object.page
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.test_list_model_object.page
@@ -9,14 +9,14 @@
     <link xref="index" group="function" type="guide"/>
     <api:function>
       <api:returns>
-        <api:type>[Regress.TestObj]</api:type>
+        <api:type>Gio.ListModel(item_type=Regress.TestObj)</api:type>
       </api:returns>
       <api:name>regress_test_list_model_object</api:name>
     </api:function>
   </info>
   <title>Regress.test_list_model_object</title>
   <synopsis><code mime="text/x-python">
-@returns([Regress.TestObj])
+@returns(Gio.ListModel(item_type=Regress.TestObj))
 def test_list_model_object():
     # Python wrapper for regress_test_list_model_object()
   </code></synopsis>


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