MCPcopy Index your code
hub / github.com/python/cpython / _finddoc

Function _finddoc

Lib/inspect.py:710–775  ·  view source on GitHub ↗
(obj, *, search_in_class=True)

Source from the content-addressed store, hash-verified

708 return cls
709
710def _finddoc(obj, *, search_in_class=True):
711 if search_in_class and isclass(obj):
712 for base in obj.__mro__:
713 if base is not object:
714 try:
715 doc = base.__doc__
716 except AttributeError:
717 continue
718 if doc is not None:
719 return doc
720 return None
721
722 if ismethod(obj):
723 name = obj.__func__.__name__
724 self = obj.__self__
725 if (isclass(self) and
726 getattr(getattr(self, name, None), '__func__') is obj.__func__):
727 # classmethod
728 cls = self
729 else:
730 cls = self.__class__
731 elif isfunction(obj):
732 name = obj.__name__
733 cls = _findclass(obj)
734 if cls is None or getattr(cls, name) is not obj:
735 return None
736 elif isbuiltin(obj):
737 name = obj.__name__
738 self = obj.__self__
739 if (isclass(self) and
740 self.__qualname__ + '.' + name == obj.__qualname__):
741 # classmethod
742 cls = self
743 else:
744 cls = self.__class__
745 # Should be tested before isdatadescriptor().
746 elif isinstance(obj, property):
747 name = obj.__name__
748 cls = _findclass(obj.fget)
749 if cls is None or getattr(cls, name) is not obj:
750 return None
751 # Should be tested before ismethoddescriptor()
752 elif isinstance(obj, functools.cached_property):
753 name = obj.attrname
754 cls = _findclass(obj.func)
755 if cls is None or getattr(cls, name) is not obj:
756 return None
757 elif ismethoddescriptor(obj) or isdatadescriptor(obj):
758 name = obj.__name__
759 cls = obj.__objclass__
760 if getattr(cls, name) is not obj:
761 return None
762 if ismemberdescriptor(obj):
763 slots = getattr(cls, '__slots__', None)
764 if isinstance(slots, dict) and name in slots:
765 return slots[name]
766 else:
767 return None

Callers 1

getdocFunction · 0.85

Calls 8

isclassFunction · 0.85
ismethodFunction · 0.85
isfunctionFunction · 0.85
_findclassFunction · 0.85
isbuiltinFunction · 0.85
ismethoddescriptorFunction · 0.85
isdatadescriptorFunction · 0.85
ismemberdescriptorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…