[pygobject] Don't mask GObject sub-class doc strings in meta-class



commit 7076669aadfc5227144df87277d69ae66865770a
Author: Tobias Mueller <gnome-bugs muelli cryptobitch de>
Date:   Sat Aug 16 17:46:50 2014 -0700

    Don't mask GObject sub-class doc strings in meta-class
    
    If a class has a __doc__ attribute explicitly set, always return it.
    Only generate doc strings for classes coming from  gi.repository
    or gi.overrides.
    
    Co-Authored-By: Simon Feltman <sfeltman src gnome org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731452
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734926

 gi/types.py             |   12 +++++++++++-
 tests/test_docstring.py |    2 --
 2 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/gi/types.py b/gi/types.py
index aa5bcb4..e244f8c 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -238,9 +238,19 @@ class GObjectMeta(_GObjectMetaBase, MetaClassHelper):
 
     @property
     def __doc__(cls):
+        """Meta class property which shows up on any class using this meta-class."""
         if cls == GObjectMeta:
             return ''
-        return generate_doc_string(cls.__info__)
+
+        doc = cls.__dict__.get('__doc__', None)
+        if doc is not None:
+            return doc
+
+        # For repository classes, dynamically generate a doc string if it wasn't overridden.
+        if cls.__module__.startswith(('gi.repository.', 'gi.overrides')):
+            return generate_doc_string(cls.__info__)
+
+        return None
 
 
 def mro(C):
diff --git a/tests/test_docstring.py b/tests/test_docstring.py
index 307e89f..7573699 100644
--- a/tests/test_docstring.py
+++ b/tests/test_docstring.py
@@ -87,7 +87,6 @@ class Test(unittest.TestCase):
         self.assertEqual(Gtk.ListStore.insert_with_valuesv.__doc__,
                          'insert_with_valuesv(self, position:int, columns:list, values:list) -> 
iter:Gtk.TreeIter')
 
-    @unittest.expectedFailure  # https://bugzilla.gnome.org/show_bug.cgi?id=731452
     def test_sub_class_doc(self):
         class A(GObject.Object):
             """first doc"""
@@ -100,7 +99,6 @@ class Test(unittest.TestCase):
         self.assertEqual(A.__doc__, "first doc")
         self.assertEqual(B.__doc__, "second doc")
 
-    @unittest.expectedFailure  # https://bugzilla.gnome.org/show_bug.cgi?id=731452
     def test_sub_class_no_doc(self):
         class A(GObject.Object):
             pass


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]