(obj)
| 102 | return cls |
| 103 | |
| 104 | def _finddoc(obj): |
| 105 | if inspect.ismethod(obj): |
| 106 | name = obj.__func__.__name__ |
| 107 | self = obj.__self__ |
| 108 | if (inspect.isclass(self) and |
| 109 | getattr(getattr(self, name, None), '__func__') is obj.__func__): |
| 110 | # classmethod |
| 111 | cls = self |
| 112 | else: |
| 113 | cls = self.__class__ |
| 114 | elif inspect.isfunction(obj): |
| 115 | name = obj.__name__ |
| 116 | cls = _findclass(obj) |
| 117 | if cls is None or getattr(cls, name) is not obj: |
| 118 | return None |
| 119 | elif inspect.isbuiltin(obj): |
| 120 | name = obj.__name__ |
| 121 | self = obj.__self__ |
| 122 | if (inspect.isclass(self) and |
| 123 | self.__qualname__ + '.' + name == obj.__qualname__): |
| 124 | # classmethod |
| 125 | cls = self |
| 126 | else: |
| 127 | cls = self.__class__ |
| 128 | # Should be tested before isdatadescriptor(). |
| 129 | elif isinstance(obj, property): |
| 130 | func = obj.fget |
| 131 | name = func.__name__ |
| 132 | cls = _findclass(func) |
| 133 | if cls is None or getattr(cls, name) is not obj: |
| 134 | return None |
| 135 | elif inspect.ismethoddescriptor(obj) or inspect.isdatadescriptor(obj): |
| 136 | name = obj.__name__ |
| 137 | cls = obj.__objclass__ |
| 138 | if getattr(cls, name) is not obj: |
| 139 | return None |
| 140 | if inspect.ismemberdescriptor(obj): |
| 141 | slots = getattr(cls, '__slots__', None) |
| 142 | if isinstance(slots, dict) and name in slots: |
| 143 | return slots[name] |
| 144 | else: |
| 145 | return None |
| 146 | for base in cls.__mro__: |
| 147 | try: |
| 148 | doc = _getowndoc(getattr(base, name)) |
| 149 | except AttributeError: |
| 150 | continue |
| 151 | if doc is not None: |
| 152 | return doc |
| 153 | return None |
| 154 | |
| 155 | def _getowndoc(obj): |
| 156 | """Get the documentation string for an object if it is not |
no test coverage detected