From: Jasper St. Pierre Date: Wed, 9 Jan 2013 15:38:01 +0000 (-0500) Subject: mallardwriter: Improve type formatting for Python X-Git-Tag: GOBJECT_INTROSPECTION_1_35_4~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d20a932d36107eed33bd57b4ce27868b8e52802e;p=platform%2Fupstream%2Fgobject-introspection.git 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. --- 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 @@ DocExamples.Obj:property-example -"property-example" {utf8: gint8} : Read / Write +"property-example" {unicode: gint8} : Read / Write

This is an example of how to document a property.

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 @@ DocExamples.Obj.vfunc -@accepts(gint) +@accepts(int) @returns(none) def do_vfunc(self, first_arg): 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 @@ - gboolean + bool doc_examples_obj_method @@ -18,15 +18,15 @@ self - gint + int first_arg - gfloat + float second_arg - gboolean + bool boolean_arg @@ -34,15 +34,15 @@ pointer_arg - utf8 + unicode string method -@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() 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 @@ - gboolean + bool doc_examples_obj_static_method - gint + int out_arg static_method -@accepts(gint) -@returns(gboolean) +@accepts(int) +@returns(bool) def static_method(out_arg): # Python wrapper for doc_examples_obj_static_method() 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 @@ - [gint] + [int] doc_examples_array_function - gint + int out_len array_function -@accepts(gint) -@returns([gint]) +@accepts(int) +@returns([int]) def array_function(out_len): # Python wrapper for doc_examples_array_function()