Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
19d5c42
attempted fix of issue #131116. Test case failing on non changed parts
lincolnj1 Mar 12, 2025
02ec2c1
Moved new test fodder to seperate file to fix errors
lincolnj1 Mar 12, 2025
8786c3c
Cleaned workspace and actually added the changed files this time
lincolnj1 Mar 12, 2025
9fe818c
Merge branch 'python:main' into getdoc-fix
lincolnj1 Mar 12, 2025
5772f7b
Seperated new tests into new test case
lincolnj1 Mar 12, 2025
f68119e
Merge branch 'getdoc-fix' of github.com:lincolnj1/cpython into getdoc…
lincolnj1 Mar 12, 2025
2406055
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 12, 2025
5f0d6d4
Merge branch 'python:main' into getdoc-fix
lincolnj1 Mar 13, 2025
d61ab34
Added more tests and versionchanged to Doc
lincolnj1 Mar 31, 2025
4b74d4e
Update Doc/library/inspect.rst
lincolnj1 Apr 1, 2025
cfe3e99
Update Lib/test/test_inspect/inspect_fodder3.py
lincolnj1 Apr 1, 2025
fa92ad3
Update Lib/test/test_inspect/inspect_fodder3.py
lincolnj1 Apr 1, 2025
d83205c
Update Lib/test/test_inspect/inspect_fodder3.py
lincolnj1 Apr 1, 2025
c4764ff
Update Lib/test/test_inspect/inspect_fodder3.py
lincolnj1 Apr 1, 2025
1b0471f
Fixed inspect_fodder3 comments and added new test cases
lincolnj1 Apr 10, 2025
d4e37c3
Merge branch 'main' into getdoc-fix
serhiy-storchaka Nov 12, 2025
1e0cb4b
Apply suggestions from code review
serhiy-storchaka Nov 12, 2025
a669d23
Update Lib/test/test_inspect/test_inspect.py
serhiy-storchaka Nov 12, 2025
c510524
Apply suggestions from code review
serhiy-storchaka Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ Retrieving source code
.. versionchanged:: 3.5
Documentation strings are now inherited if not overridden.

.. versionchanged:: next
Documentation strings on :class:`~functools.cached_property`
objects are now inherited if not overriden.


.. function:: getcomments(object)

Expand Down
6 changes: 6 additions & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ def _finddoc(obj):
cls = _findclass(obj.fget)
if cls is None or getattr(cls, name) is not obj:
return None
# Should be tested before ismethoddescriptor()
elif isinstance(obj, functools.cached_property):
name = obj.attrname
cls = _findclass(obj.func)
if cls is None or getattr(cls, name) is not obj:
return None
elif ismethoddescriptor(obj) or isdatadescriptor(obj):
name = obj.__name__
cls = obj.__objclass__
Expand Down
34 changes: 34 additions & 0 deletions Lib/test/test_inspect/inspect_fodder3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from functools import cached_property

# Docstring in parent, inherited in child
class ParentInheritDoc:
@cached_property
def foo(self):
"""docstring for foo defined in parent"""

class ChildInheritDoc(ParentInheritDoc):
@cached_property
def foo(self):
pass

# Redine foo as something other than cached_property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Redine foo as something other than cached_property
# redefine foo as something other than cached_property

class ChildPropertyFoo(ParentInheritDoc):
@property
def foo(self):
"""docstring for the property foo"""
pass

class ChildMethodFoo(ParentInheritDoc):
def foo(self):
"""docstring for the method foo"""

# Docstring in child but not parent
class ParentNoDoc:
@cached_property
def foo(self):
pass

class ChildDefineDoc(ParentNoDoc):
@cached_property
def foo(self):
"""docstring for foo defined in child"""
15 changes: 15 additions & 0 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

from test.test_inspect import inspect_fodder as mod
from test.test_inspect import inspect_fodder2 as mod2
from test.test_inspect import inspect_fodder3 as mod3
from test.test_inspect import inspect_stringized_annotations
from test.test_inspect import inspect_deferred_annotations

Expand Down Expand Up @@ -665,6 +666,20 @@ def test_getdoc_inherited(self):
self.assertEqual(inspect.getdoc(mod.FesteringGob.contradiction),
'The automatic gainsaying.')

def test_getdoc_inherited_cached_property(self):
self.assertEqual(inspect.getdoc(mod3.ChildInheritDoc.foo),
'docstring for foo defined in parent')

def test_getdoc_redefine_cached_property_as_other(self):
self.assertEqual(inspect.getdoc(mod3.ChildPropertyFoo.foo),
'docstring for the property foo')
self.assertEqual(inspect.getdoc(mod3.ChildMethodFoo.foo),
'docstring for the method foo')

def test_getdoc_define_cached_property(self):
self.assertEqual(inspect.getdoc(mod3.ChildDefineDoc.foo),
'docstring for foo defined in child')

@unittest.skipIf(MISSING_C_DOCSTRINGS, "test requires docstrings")
def test_finddoc(self):
finddoc = inspect._finddoc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:func:`inspect.getdoc` now correctly returns an inherited docstring on :class:`~functools.cached_property` objects if none is given in a subclass.
Loading