This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect.getdoc fails on objs that use property for __doc__
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: collinwinter, drewp, georg.brandl, georg.brandl, nnorwitz
Priority: normal Keywords:

Created on 2005-11-26 21:42 by drewp, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg26923 - (view) Author: Drew Perttula (drewp) Date: 2005-11-26 21:42
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)

msg26924 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2006-02-01 11:35
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.
msg26925 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 08:21
Logged In: YES 
user_id=1188172

I don't know. Neal, do you have an opinion about property
docstrings?
msg26926 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-03-20 08:04
Logged In: YES 
user_id=33168

That code doesn't work if doc is unicode.  I'm not sure how
to achieve what you want.
msg26927 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-04-12 15:19
Logged In: YES 
user_id=849994

Closing as Won't Fix.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42626
2005-11-26 21:42:32drewpcreate