classification
Title: inspect.getdoc does find inherited property __doc__
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: jayvdb, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-10-29 04:53 by jayvdb, last changed 2015-10-29 06:22 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
getdoc-property.diff jayvdb, 2015-10-29 04:53 Fix and test case review
Messages (3)
msg253653 - (view) Author: John Mark Vandenberg (jayvdb) * Date: 2015-10-29 04:53
inspect.getdoc's helper _finddoc raises an AttributeError on encountering a property, which is silently discarded.

>>> class Foo(object):
...     @property
...     def foo(self):
...         """foobar."""
...         return 'foo'
... 
>>> class Bar(Foo):
...     @property
...     def foo(self):
...         return 'bar'
... 
>>> import inspect
>>> inspect.getdoc(Foo.foo)
'foobar.'
>>> inspect.getdoc(Bar.foo)
>>>

How I came upon this was doing static code analysis, and the f.fget on line 522 here looks very wrong.

http://bugs.python.org/review/15582/diff/14140/Lib/inspect.py

This code dedicated to supporting `property` does not work because of that, but also because a property is also a data descriptor so the 'property' branch is never executed.

>>> inspect.isdatadescriptor(property())
True
msg253659 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-10-29 06:20
New changeset bbf00faf25ff by Serhiy Storchaka in branch '3.5':
Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties.
https://hg.python.org/cpython/rev/bbf00faf25ff

New changeset e80d1e9737d4 by Serhiy Storchaka in branch 'default':
Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties.
https://hg.python.org/cpython/rev/e80d1e9737d4
msg253660 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-10-29 06:22
Thank you John for your report and your patch.

Committed tests are slightly changed because "contradiction" was originally purposed to test properties.
History
Date User Action Args
2015-10-29 06:22:55serhiy.storchakasetstatus: open -> closed
messages: + msg253660

assignee: serhiy.storchaka
resolution: fixed
stage: resolved
2015-10-29 06:20:42python-devsetnosy: + python-dev
messages: + msg253659
2015-10-29 04:59:16jayvdbsetnosy: + serhiy.storchaka
2015-10-29 04:53:40jayvdbcreate