summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-01-01 20:23:17 -0800
committerSimon Feltman <sfeltman@src.gnome.org>2014-01-01 20:23:17 -0800
commit07abf8343bbeac6f36d370ced654fa6506b22175 (patch)
treee1ccba0f9db1a9847e2c89804fa225d2f3886bc6
parente8359847136e9ad76a670a382c0abc61cb4e81d3 (diff)
downloadpygobject-07abf8343bbeac6f36d370ced654fa6506b22175.tar.gz
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
-rw-r--r--gi/docstring.py9
-rw-r--r--tests/test_docstring.py18
2 files changed, 24 insertions, 3 deletions
diff --git a/gi/docstring.py b/gi/docstring.py
index 1a188ecd..77332e86 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 71f1b838..e956f7de 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)