gh-131116: Fix inspect.getdoc() to work with cached_property objects (GH-131165)

This commit is contained in:
Jacob Austin Lincoln 2025-11-12 02:07:21 -08:00 committed by GitHub
parent 23d85a2a3f
commit 70748bdbea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 70 additions and 0 deletions

View file

@ -747,6 +747,12 @@ def _finddoc(obj, *, search_in_class=True):
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__