diff options
-rw-r--r-- | gi/docstring.py | 9 | ||||
-rw-r--r-- | tests/test_docstring.py | 18 |
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) |