[gobject-introspection/wip/doctool-improvements] mallardwriter: Improve type formatting for Python
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/doctool-improvements] mallardwriter: Improve type formatting for Python
- Date: Wed, 9 Jan 2013 19:10:17 +0000 (UTC)
commit d20a932d36107eed33bd57b4ce27868b8e52802e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Jan 9 10:38:01 2013 -0500
mallardwriter: Improve type formatting for Python
Rather than use the glib names like gint/gchar and friends, use the
Python type names. Right now, this is Python 2, but we'll soon be
introducing a special Python 3 formatter.
giscanner/mallardwriter.py | 26 +++++++++++++++++++-
.../DocExamples.Obj-property-example.page | 2 +-
.../DocExamples.Obj-vfunc.page | 2 +-
.../DocExamples.Obj.method.page | 14 +++++-----
.../DocExamples.Obj.static_method.page | 8 +++---
.../DocExamples.array_function.page | 8 +++---
6 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py
index 801df08..5a9f094 100644
--- a/giscanner/mallardwriter.py
+++ b/giscanner/mallardwriter.py
@@ -374,6 +374,30 @@ class MallardFormatterPython(MallardFormatter):
else:
return parameter.argname
+ def format_fundamental_type(self, name):
+ fundamental_types = {
+ "utf8": "unicode",
+ "gunichar": "unicode",
+ "gchar": "str",
+ "guchar": "str",
+ "gboolean": "bool",
+ "gint": "int",
+ "guint": "int",
+ "glong": "int",
+ "gulong": "int",
+ "gint64": "int",
+ "guint64": "int",
+ "gfloat": "float",
+ "gdouble": "float",
+ "gchararray": "str",
+ "GParam": "GLib.Param",
+ "PyObject": "object",
+ "GStrv": "[str]",
+ "GVariant": "GLib.Variant",
+ }
+
+ return fundamental_types.get(name, name)
+
def format_type(self, type_):
if isinstance(type_, ast.Array):
return '[' + self.format_type(type_.element_type) + ']'
@@ -383,7 +407,7 @@ class MallardFormatterPython(MallardFormatter):
elif type_.target_giname is not None:
return type_.target_giname
else:
- return type_.target_fundamental
+ return self.format_fundamental_type(type_.target_fundamental)
def format_function_name(self, func):
if func.parent is not None:
diff --git a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-property-example.page b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-property-example.page
index be1e239..43f4b56 100644
--- a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-property-example.page
+++ b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-property-example.page
@@ -10,7 +10,7 @@
</info>
<title>DocExamples.Obj:property-example</title>
<synopsis><code mime="text/x-python">
-"property-example" {utf8: gint8} : Read / Write
+"property-example" {unicode: gint8} : Read / Write
</code></synopsis>
<p>This is an example of how to document a property.</p>
</page>
diff --git a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-vfunc.page b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-vfunc.page
index 4e394d2..4f56bae 100644
--- a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-vfunc.page
+++ b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj-vfunc.page
@@ -11,7 +11,7 @@
</info>
<title>DocExamples.Obj.vfunc</title>
<synopsis><code mime="text/x-python">
- accepts(gint)
+ accepts(int)
@returns(none)
def do_vfunc(self, first_arg):
</code></synopsis>
diff --git a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.method.page b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.method.page
index 8447be6..ab20921 100644
--- a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.method.page
+++ b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.method.page
@@ -10,7 +10,7 @@
<link type="guide" xref="DocExamples.Obj" group="method"/>
<api:function>
<api:returns>
- <api:type>gboolean</api:type>
+ <api:type>bool</api:type>
</api:returns>
<api:name>doc_examples_obj_method</api:name>
<api:arg>
@@ -18,15 +18,15 @@
<api:name>self</api:name>
</api:arg>
<api:arg>
- <api:type>gint</api:type>
+ <api:type>int</api:type>
<api:name>first_arg</api:name>
</api:arg>
<api:arg>
- <api:type>gfloat</api:type>
+ <api:type>float</api:type>
<api:name>second_arg</api:name>
</api:arg>
<api:arg>
- <api:type>gboolean</api:type>
+ <api:type>bool</api:type>
<api:name>boolean_arg</api:name>
</api:arg>
<api:arg>
@@ -34,15 +34,15 @@
<api:name>pointer_arg</api:name>
</api:arg>
<api:arg>
- <api:type>utf8</api:type>
+ <api:type>unicode</api:type>
<api:name>string</api:name>
</api:arg>
</api:function>
</info>
<title>method</title>
<synopsis><code mime="text/x-python">
- accepts(gint, gfloat, gboolean, gpointer, utf8)
- returns(gboolean)
+ accepts(int, float, bool, gpointer, unicode)
+ returns(bool)
def method(self, first_arg, second_arg, boolean_arg, pointer_arg, string):
# Python wrapper for doc_examples_obj_method()
</code></synopsis>
diff --git a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.static_method.page b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.static_method.page
index 1ace519..35c6c7b 100644
--- a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.static_method.page
+++ b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.Obj.static_method.page
@@ -10,19 +10,19 @@
<link type="guide" xref="DocExamples.Obj" group="function"/>
<api:function>
<api:returns>
- <api:type>gboolean</api:type>
+ <api:type>bool</api:type>
</api:returns>
<api:name>doc_examples_obj_static_method</api:name>
<api:arg>
- <api:type>gint</api:type>
+ <api:type>int</api:type>
<api:name>out_arg</api:name>
</api:arg>
</api:function>
</info>
<title>static_method</title>
<synopsis><code mime="text/x-python">
- accepts(gint)
- returns(gboolean)
+ accepts(int)
+ returns(bool)
def static_method(out_arg):
# Python wrapper for doc_examples_obj_static_method()
</code></synopsis>
diff --git a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.array_function.page b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.array_function.page
index 3a0d054..dd686f8 100644
--- a/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.array_function.page
+++ b/tests/doctool/DocExamples-1.0-Python-expected/DocExamples.array_function.page
@@ -10,19 +10,19 @@
<link type="guide" xref="index" group="function"/>
<api:function>
<api:returns>
- <api:type>[gint]</api:type>
+ <api:type>[int]</api:type>
</api:returns>
<api:name>doc_examples_array_function</api:name>
<api:arg>
- <api:type>gint</api:type>
+ <api:type>int</api:type>
<api:name>out_len</api:name>
</api:arg>
</api:function>
</info>
<title>array_function</title>
<synopsis><code mime="text/x-python">
- accepts(gint)
- returns([gint])
+ accepts(int)
+ returns([int])
def array_function(out_len):
# Python wrapper for doc_examples_array_function()
</code></synopsis>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]