Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added more tests and versionchanged to Doc
  • Loading branch information
lincolnj1 committed Mar 31, 2025
commit d61ab34248a43482b204c3e6ca4e102df3a3c50d
3 changes: 3 additions & 0 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ Retrieving source code
.. versionchanged:: 3.5
Documentation strings are now inherited if not overridden.

.. versionchanged:: next
Now correctly returns an inherited docstring on :class:`~functools.cached_property` objects if not overridden.
Comment thread
lincolnj1 marked this conversation as resolved.
Outdated


.. function:: getcomments(object)

Expand Down
28 changes: 25 additions & 3 deletions Lib/test/test_inspect/inspect_fodder3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
from functools import cached_property

Comment thread
picnixz marked this conversation as resolved.
class Parent:
# Docstring in parent, inherited in child
Comment thread
picnixz marked this conversation as resolved.
Outdated
class ParentInheritDoc:
@cached_property
def foo(self):
"this is the docstring for foo"
"docstring for foo defined in parent"
Comment thread
lincolnj1 marked this conversation as resolved.
Outdated

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

# Redine foo as something other than cached_property
Copy link
Copy Markdown
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"
Comment thread
lincolnj1 marked this conversation as resolved.
Outdated
pass
Comment thread
serhiy-storchaka marked this conversation as resolved.
Outdated

class Child(Parent):
class ChildMethodFoo(ParentInheritDoc):
def foo(self):
"docstring for the method foo"
Comment thread
lincolnj1 marked this conversation as resolved.
Outdated

# Docstring in child but not parent
Comment thread
picnixz marked this conversation as resolved.
Outdated
class ParentNoDoc:
@cached_property
def foo(self):
pass
Comment thread
lincolnj1 marked this conversation as resolved.

class ChildDefineDoc(ParentNoDoc):
@cached_property
def foo(self):
"docstring for foo defined in child"
Comment thread
lincolnj1 marked this conversation as resolved.
Outdated
14 changes: 12 additions & 2 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,18 @@ def test_getdoc_inherited(self):
'The automatic gainsaying.')

def test_getdoc_inherited_cached_property(self):
self.assertEqual(inspect.getdoc(mod3.Parent.foo),
inspect.getdoc(mod3.Child.foo))
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
inspect.getdoc(), if run on a cached_property that does not define a docstring but inherits from a class that did define a docstring, will now return the inherited docstring rather than None.
:func:`inspect.getdoc` now correctly returns an inherited docstring on :class:`~functools.cached_property` objects if none is given in a subclass.
Comment thread
serhiy-storchaka marked this conversation as resolved.
Outdated
Loading