[ python-Bugs-1367183 ] inspect.getdoc fails on objs that use property for __doc__

SourceForge.net noreply at sourceforge.net
Wed Feb 1 12:35:46 CET 2006


Bugs item #1367183, was opened at 2005-11-26 16:42
Message generated for change (Comment added) made by collinwinter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1367183&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Drew Perttula (drewp)
Assigned to: Nobody/Anonymous (nobody)
Summary: inspect.getdoc fails on objs that use property for __doc__

Initial Comment:
inspect.getdoc has these lines:

     if not isinstance(doc, types.StringTypes):
         return None

which interfere with the case where __doc__ is some
other thing that has a good __str__. I wanted to make a
lazy __doc__ that did an expensive lookup of some
external documentation only when it was str()'d, but
since doc displayers often (correctly) use
inspect.getdoc, they were getting None.

I think the intention of the test in getdoc() is to
avoid trying string operations on a __doc__ that is
None. I think that a more lenient version would allow
me to do my fancy docstrings but still solve the
'__doc__ is None' problem. Please consider the
following patch:

if doc is None:
     return None
doc = str(doc)



----------------------------------------------------------------------

Comment By: Collin Winter (collinwinter)
Date: 2006-02-01 06:35

Message:
Logged In: YES 
user_id=1344176

It's not a good idea to use properties for __doc__:

"""
>>> class Foo(object):
...    def _get(self):
...        return 'the docstring'
...    __doc__ = property(_get)
...
>>> print Foo().__doc__
the docstring
>>> print Foo.__doc__
<property object at 0xb7b3a234>
>>>
"""

In this light, I don't view inspect.getdoc's lack of support
for __doc__-as-property as a bug.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1367183&group_id=5470


More information about the Python-bugs-list mailing list