-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-131116: Fix inspect._finddoc to work with cached_property objects. #131165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
19d5c42
02ec2c1
8786c3c
9fe818c
5772f7b
f68119e
2406055
5f0d6d4
d61ab34
4b74d4e
cfe3e99
fa92ad3
d83205c
c4764ff
1b0471f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||
| 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): pass | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| class ChildInheritDefineDoc(ParentInheritDoc): | ||||||||
| @cached_property | ||||||||
| def foo(self): | ||||||||
| pass | ||||||||
|
|
||||||||
| # Redefine foo as something other than cached_property | ||||||||
| class ChildPropertyFoo(ParentInheritDoc): | ||||||||
| @property | ||||||||
| def foo(self): | ||||||||
| """docstring for the property foo""" | ||||||||
| pass | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| 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 ChildNoDoc(ParentNoDoc): pass | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| class ChildDefineDoc(ParentNoDoc): | ||||||||
| @cached_property | ||||||||
| def foo(self): | ||||||||
| """docstring for foo defined in child""" | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -665,6 +666,26 @@ 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') | ||||||||||||||||||
| self.assertEqual(inspect.getdoc(mod3.ChildInheritDefineDoc.foo), | ||||||||||||||||||
| 'docstring for foo defined in parent') | ||||||||||||||||||
|
Comment on lines
+670
to
+673
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| 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') | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_getdoc_nodoc_inherited(self): | ||||||||||||||||||
| self.assertEqual(inspect.getdoc(mod3.ChildNoDoc.foo), | ||||||||||||||||||
| None) | ||||||||||||||||||
|
Comment on lines
+686
to
+687
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| @unittest.skipIf(MISSING_C_DOCSTRINGS, "test requires docstrings") | ||||||||||||||||||
| def test_finddoc(self): | ||||||||||||||||||
| finddoc = inspect._finddoc | ||||||||||||||||||
|
|
||||||||||||||||||
| 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. | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.