Commit 7b7277f3 authored by Simon Feltman's avatar Simon Feltman
Browse files

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
parent c5343d32
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment