[pygobject] Set Property instance doc string and blurb to getter doc string



commit 7b7277f3cc099280f8e2d6cf6693490290fedc24
Author: Simon Feltman <sfeltman src gnome org>
Date:   Fri Nov 9 19:17:03 2012 -0800

    Set Property instance doc string and blurb to getter doc string
    
    Assign Property getter __doc__ strings or explicit blurb parameters
    to the Property instances __doc__ attribute. This clobbers the
    default Property classes lengthy and unhelpful doc string in the case
    of instances.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688025

 gi/_gobject/propertyhelper.py |   10 +++++++---
 tests/test_properties.py      |   14 ++++++++++----
 2 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/gi/_gobject/propertyhelper.py b/gi/_gobject/propertyhelper.py
index 92abca2..9e44af4 100644
--- a/gi/_gobject/propertyhelper.py
+++ b/gi/_gobject/propertyhelper.py
@@ -162,6 +162,10 @@ class Property(object):
         if not isinstance(blurb, _basestring):
             raise TypeError("blurb must be a string")
         self.blurb = blurb
+        # Always clobber __doc__ with blurb even if blurb is empty because
+        # we don't want the lengthy Property class documentation showing up
+        # on instances.
+        self.__doc__ = blurb
 
         if flags < 0 or flags > 32:
             raise TypeError("invalid flag value: %r" % (flags,))
@@ -234,10 +238,10 @@ class Property(object):
 
     def getter(self, fget):
         """Set the getter function to fget. For use as a decorator."""
-        if self.__doc__ is None:
-            self.__doc__ = fget.__doc__
-        if not self.blurb and fget.__doc__:
+        if fget.__doc__:
+            # Always clobber docstring and blurb with the getter docstring.
             self.blurb = fget.__doc__
+            self.__doc__ = fget.__doc__
         self.fget = fget
         return self
 
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 008efc3..fb29045 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -719,14 +719,20 @@ class TestProperty(unittest.TestCase):
         del t
         self.assertEqual(sys.getrefcount(o), rc)
 
-    def test_doc_string_as_blurb(self):
+    def test_doc_strings(self):
         class C(GObject.GObject):
+            foo_blurbed = GObject.Property(type=int, blurb='foo_blurbed doc string')
+
             @GObject.Property
-            def blurbed(self):
-                """blurbed doc string"""
+            def foo_getter(self):
+                """foo_getter doc string"""
                 return 0
 
-        self.assertEqual(C.blurbed.blurb, 'blurbed doc string')
+        self.assertEqual(C.foo_blurbed.blurb, 'foo_blurbed doc string')
+        self.assertEqual(C.foo_blurbed.__doc__, 'foo_blurbed doc string')
+
+        self.assertEqual(C.foo_getter.blurb, 'foo_getter doc string')
+        self.assertEqual(C.foo_getter.__doc__, 'foo_getter doc string')
 
     def test_python_to_glib_type_mapping(self):
         tester = GObject.Property()



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