[pygobject] docs: Skip display of default constructor for disguised structs
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] docs: Skip display of default constructor for disguised structs
- Date: Thu, 2 Jan 2014 04:28:41 +0000 (UTC)
commit 07abf8343bbeac6f36d370ced654fa6506b22175
Author: Simon Feltman <sfeltman src gnome org>
Date: Wed Jan 1 20:23:17 2014 -0800
docs: Skip display of default constructor for disguised structs
Structs which have zero length should now show a default constructor.
Structs with a length should not show keyword arguments in the default
constructor.
https://bugzilla.gnome.org/show_bug.cgi?id=708060
gi/docstring.py | 9 ++++++++-
tests/test_docstring.py | 18 ++++++++++++++++--
2 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/gi/docstring.py b/gi/docstring.py
index 1a188ec..77332e8 100644
--- a/gi/docstring.py
+++ b/gi/docstring.py
@@ -181,7 +181,14 @@ def _generate_callable_info_doc(info):
def _generate_class_info_doc(info):
doc = '\n:Constructors:\n' # start with \n to avoid auto indent of other lines
- doc += ' ' + info.get_name() + '(**properties)\n'
+
+ if isinstance(info, StructInfo):
+ # Don't show default constructor for disguised (0 length) structs
+ if info.get_size() > 0:
+ doc += ' ' + info.get_name() + '()\n'
+ else:
+ doc += ' ' + info.get_name() + '(**properties)\n'
+
for method_info in info.get_methods():
if method_info.is_constructor():
doc += ' ' + _generate_callable_info_doc(method_info) + '\n'
diff --git a/tests/test_docstring.py b/tests/test_docstring.py
index 71f1b83..e956f7d 100644
--- a/tests/test_docstring.py
+++ b/tests/test_docstring.py
@@ -5,6 +5,14 @@ from gi.docstring import _get_pytype_hint
from gi.repository import GIMarshallingTests
from gi.repository import Gio
+try:
+ import cairo
+ cairo = cairo
+ has_cairo = True
+ from gi.repository import Regress
+except ImportError:
+ has_cairo = False
+
class Test(unittest.TestCase):
def test_api(self):
@@ -70,10 +78,16 @@ class Test(unittest.TestCase):
self.assertEqual(GIMarshallingTests.init_function.__doc__,
'init_function(argv:list=None) -> argv:list')
- def tests_class_doc_constructors(self):
+ def test_class_doc_constructors(self):
doc = GIMarshallingTests.Object.__doc__
self.assertTrue('new(int_:int)' in doc)
- def tests_struct_doc_constructors(self):
+ def test_struct_doc_constructors(self):
doc = GIMarshallingTests.BoxedStruct.__doc__
self.assertTrue('new()' in doc)
+ self.assertTrue('BoxedStruct()' in doc)
+
+ @unittest.skipUnless(has_cairo, 'built without cairo support')
+ def test_private_struct_constructors(self):
+ doc = Regress.TestBoxedPrivate.__doc__
+ self.assertTrue('TestBoxedPrivate()' not in doc)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]