René's URL Explorer Experiment


Title: `inspect.getdoc()` failing to return docstring for cached_property for subclass that overrides code but not docstring · Issue #131116 · python/cpython · GitHub

Open Graph Title: `inspect.getdoc()` failing to return docstring for cached_property for subclass that overrides code but not docstring · Issue #131116 · python/cpython

X Title: `inspect.getdoc()` failing to return docstring for cached_property for subclass that overrides code but not docstring · Issue #131116 · python/cpython

Description: Bug report Bug description: When a child/sub-class inherits a method from its parent/base-class, inspect.getdoc(...) returns the parent's method's docstring when the child's method does not have its own docstring. This is true even if th...

Open Graph Description: Bug report Bug description: When a child/sub-class inherits a method from its parent/base-class, inspect.getdoc(...) returns the parent's method's docstring when the child's method does not have it...

X Description: Bug report Bug description: When a child/sub-class inherits a method from its parent/base-class, inspect.getdoc(...) returns the parent's method's docstring when the child's method does...

Opengraph URL: https://github.com/python/cpython/issues/131116

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`inspect.getdoc()` failing to return docstring for cached_property for subclass that overrides code but not docstring","articleBody":"# Bug report\n\n### Bug description:\n\nWhen a child/sub-class inherits a method from its parent/base-class, `inspect.getdoc(...)` returns the parent's method's docstring when the child's method does not have its own docstring. This is true even if the child overwrites the method but doesn't have a docstring as part of that.\n\nHowever, this is failing when the method has the `functools.cached_property` decorator on it and the method is overwritten in the child. The below code errors on the assertion.\n\n```python\nfrom functools import cached_property\nimport inspect\n\nclass Parent:\n    @cached_property\n    def foo(self):\n        \"this is the docstring for foo\"\n        return 1\n\nclass Child(Parent):\n    @cached_property\n    def foo(self): ...\n\nassert inspect.getdoc(Child.foo) == inspect.getdoc(Parent.foo) # fails but we want this to be True\n```\n\nI did my best to test this across a variety of similar things and this was the only case where I found the docstring to not be inherited. I tested across methods, properties (with the `@property` decorator), cached_properties, static_methods, and class_methods; and having the child explicitly overwrite the code (but not the docstring) of the method or not.\n\nThe below test code shows passes for all those other scenarios but only fails on `test_cached_property_defined_in_parent_and_child`.\n\n```python\nfrom functools import cached_property\nimport inspect\n\nimport unittest\n\n\nclass TestMatchingDocstrings(unittest.TestCase):\n    def setUp(self):\n        self.parent_class = ParentClass\n        self.child_class = ChildClass\n\n    def compare_docstrings(self, attrname):\n        parent_attr = getattr(self.parent_class, attrname)\n        parent_docstring = inspect.getdoc(parent_attr)\n        child_attr = getattr(self.child_class, attrname)\n        child_docstring = inspect.getdoc(child_attr)\n        self.assertEqual(parent_docstring, child_docstring)\n\n    def test_method_defined_in_parent_only(self):\n        self.compare_docstrings(\"method_defined_in_parent_only\")\n\n    def test_method_defined_in_parent_and_child(self):\n        self.compare_docstrings(\"method_defined_in_parent_and_child\")\n\n    def test_property_defined_in_parent_only(self):\n        self.compare_docstrings(\"property_defined_in_parent_only\")\n\n    def test_property_defined_in_parent_and_child(self):\n        self.compare_docstrings(\"property_defined_in_parent_and_child\")\n\n    def test_cached_property_defined_in_parent_only(self):\n        self.compare_docstrings(\"cached_property_defined_in_parent_only\")\n\n    def test_cached_property_defined_in_parent_and_child(self):\n        self.compare_docstrings(\"cached_property_defined_in_parent_and_child\")\n\n    def test_static_method_defined_in_parent_only(self):\n        self.compare_docstrings(\"static_method_defined_in_parent_only\")\n\n    def test_static_method_defined_in_parent_and_child(self):\n        self.compare_docstrings(\"static_method_defined_in_parent_and_child\")\n\n    def test_class_method_defined_in_parent_only(self):\n        self.compare_docstrings(\"class_method_defined_in_parent_only\")\n\n    def test_class_method_defined_in_parent_and_child(self):\n        self.compare_docstrings(\"class_method_defined_in_parent_and_child\")\n\n\nclass ParentClass:\n    def method_defined_in_parent_only(self):\n        \"This is a method in the parent only\"\n\n    def method_defined_in_parent_and_child(self):\n        \"This is a method in the parent and child\"\n\n    @property\n    def property_defined_in_parent_only(self):\n        \"This is a property with the decorator in the parent only\"\n\n    @property\n    def property_defined_in_parent_and_child(self):\n        \"This is a property with the decorator in the parent and child\"\n\n    @cached_property\n    def cached_property_defined_in_parent_only(self):\n        \"This is a cached property with the decorator in the parent only\"\n\n    @cached_property\n    def cached_property_defined_in_parent_and_child(self):\n        \"This is a cached property with the decorator in the parent and child\"\n\n    @staticmethod\n    def static_method_defined_in_parent_only():\n        \"This is a static method with the decorator in the parent only\"\n\n    @staticmethod\n    def static_method_defined_in_parent_and_child():\n        \"This is a static method with the decorator in the parent and child\"\n\n    @classmethod\n    def class_method_defined_in_parent_only(cls):\n        \"This is a class method with the decorator in the parent only\"\n\n    @classmethod\n    def class_method_defined_in_parent_and_child(cls):\n        \"This is a class method with the decorator in the parent and child\"\n\n\nclass ChildClass(ParentClass):\n    def method_defined_in_parent_and_child(self): ...\n\n    @property\n    def property_defined_in_parent_and_child(self): ...\n\n    @cached_property\n    def cached_property_defined_in_parent_and_child(self): ...\n\n    @staticmethod\n    def static_method_defined_in_parent_and_child(): ...\n\n    @classmethod\n    def class_method_defined_in_parent_and_child(cls): ...\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n```\n\n\n\n### CPython versions tested on:\n\n3.9, 3.10, 3.11, 3.12, 3.13, 3.14\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-131165\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/scotscotmcc","@type":"Person","name":"scotscotmcc"},"datePublished":"2025-03-11T22:18:46Z","url":"https://github.com/python/cpython/issues/131116"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:10cf1b58-8466-5f6b-6b5c-14a7ebf0a047
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDBA6:A3F58:391BC2:4C5831:6AECCA57
html-safe-nonced7809a7b526a1e7041e821eeaa0d8942360c95eb14e7b6d55ff62d6b6f9c03b4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkE2OkEzRjU4OjM5MUJDMjo0QzU4MzE6NkFFQ0NBNTciLCJ2aXNpdG9yX2lkIjoiNzU3Mjg4ODY2MzE4MTE2NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac555becf76166d9e97b4143876c9ad970983fb7760a9fa6f53f88e2f83ab1093f
hovercard-subject-tagissue:2912005657
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/131116/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b2643a7bb2273937c6da8fa8db87cad509f06661caafd674675ef332c9b0f66a/python/cpython/issues/131116
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b2643a7bb2273937c6da8fa8db87cad509f06661caafd674675ef332c9b0f66a/python/cpython/issues/131116
og:image:altBug report Bug description: When a child/sub-class inherits a method from its parent/base-class, inspect.getdoc(...) returns the parent's method's docstring when the child's method does not have it...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamescotscotmcc
hostnamegithub.com
expected-hostnamegithub.com
Nonedc0b519c5798dc1150b88dc4c06a8b9634d0069218dc04e469970e76aad74016
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedb139f0bf57b59bf9a8c4abb0849924d6c6ca559
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/131116#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F131116
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F131116
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/131116
Reloadhttps://github.com/python/cpython/issues/131116
Reloadhttps://github.com/python/cpython/issues/131116
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.3k (2.3k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/pulse
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/131116
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/131116
inspect.getdoc() failing to return docstring for cached_property for subclass that overrides code but not docstringhttps://github.com/python/cpython/issues/131116#top
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/scotscotmcc
scotscotmcchttps://github.com/scotscotmcc
on Mar 11, 2025https://github.com/python/cpython/issues/131116#issue-2912005657
gh-131116: Fix inspect._finddoc to work with cached_property objects. #131165https://github.com/python/cpython/pull/131165
scotscotmcchttps://github.com/scotscotmcc
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Mar 11, 2025https://github.com/python/cpython/issues/131116#event-16698875244
https://github.com/lincolnj1
lincolnj1https://github.com/lincolnj1
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2716489440
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2717003507
picnixzhttps://github.com/picnixz
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Mar 12, 2025https://github.com/python/cpython/issues/131116#event-16713021912
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2717763088
https://github.com/scotscotmcc
scotscotmcchttps://github.com/scotscotmcc
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2718067471
https://private-user-images.githubusercontent.com/83373712/421930420-417a0e6f-8915-4be8-aa75-afb028915e2b.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTM5MDM0OTIsIm5iZiI6MTc5MzkwMzE5MiwicGF0aCI6Ii84MzM3MzcxMi80MjE5MzA0MjAtNDE3YTBlNmYtODkxNS00YmU4LWFhNzUtYWZiMDI4OTE1ZTJiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTA1VDE4MjYzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFkM2I1MzlmNjJiOWU5YzgzOTJmMjc5ODEwNzFlMGUwZmIyMTczNGRlMTM0MTNjNmU0Y2NmZDE5MzcyN2Y5YzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.Qct8kXP8XNsYDgvRcuFiPAWVvfBl3n9dPA76JardFSo
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2718079645
https://github.com/lincolnj1
lincolnj1https://github.com/lincolnj1
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2718428127
https://github.com/scotscotmcc
scotscotmcchttps://github.com/scotscotmcc
on Mar 12, 2025https://github.com/python/cpython/issues/131116#issuecomment-2718532660
picnixzhttps://github.com/picnixz
Inspect issues 🔍https://github.com/orgs/python/projects/45
on Mar 12, 2025https://github.com/python/cpython/issues/131116#event-16718523634
lincolnj1https://github.com/lincolnj1
on Mar 12, 2025https://github.com/python/cpython/issues/131116#event-16719226229
attempted fix of issue python#131116. Test case failing on non change…https://github.com/lincolnj1/cpython/commit/19d5c42b09a57c5d93ee9cd391ab21b8ea55ba90
python#131116https://github.com/python/cpython/issues/131116
19d5c42https://github.com/lincolnj1/cpython/commit/19d5c42b09a57c5d93ee9cd391ab21b8ea55ba90
serhiy-storchakahttps://github.com/serhiy-storchaka
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Nov 12, 2025https://github.com/python/cpython/issues/131116#event-20883915159
serhiy-storchakahttps://github.com/serhiy-storchaka
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 12, 2025https://github.com/python/cpython/issues/131116#event-20883919163
github-project-automationhttps://github.com/apps/github-project-automation
Inspect issues 🔍https://github.com/orgs/python/projects/45
on Nov 12, 2025https://github.com/python/cpython/issues/131116
serhiy-storchakahttps://github.com/serhiy-storchaka
on Nov 12, 2025https://github.com/python/cpython/issues/131116#event-20884419696
gh-131116: Fix inspect.getdoc() to work with cached_property objects (G…https://github.com/python/cpython/commit/70748bdbea872a84dd8eadad9b48c73e218d2e1f
gh-131116https://github.com/python/cpython/issues/131116
G…https://github.com/python/cpython/pull/131165
70748bdhttps://github.com/python/cpython/commit/70748bdbea872a84dd8eadad9b48c73e218d2e1f
StanFromIrelandhttps://github.com/StanFromIreland
on Dec 6, 2025https://github.com/python/cpython/issues/131116#event-21401823040
pythongh-131116: Fix inspect.getdoc() to work with cached_property ob…https://github.com/StanFromIreland/cpython/commit/165694168529e807d3d024722778285da4e554a8
pythongh-131116https://github.com/python/cpython/issues/131116
1656941https://github.com/StanFromIreland/cpython/commit/165694168529e807d3d024722778285da4e554a8
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/131116
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/131116
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
Inspect issues 🔍https://github.com/orgs/python/projects/45
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.