Doc strings in descriptors
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun May 3 03:21:06 EDT 2009
On Sat, 02 May 2009 23:36:26 -0500, Kevin D. Smith wrote:
> I have a simple descriptor to create a cached property as shown below.
...
> What do I need to do to get the doc string of the wrapped function to
> apper when using help()?
Call it on the class, not the instance:
>>> class Test(object):
... def getx(self): return "spam"
... def setx(self, value): return None # and do nothing
... x = property(getx, setx, None, "This is my docstring")
...
>>> t = Test()
>>> t.x.__doc__ # like "spam".__doc__
'str(object) -> string\n\nReturn a nice string representation of the
object.\nIf the argument is a string, the return value is the same
object.'
>>> Test.x.__doc__
'This is my docstring'
--
Steven
More information about the Python-list
mailing list