Stable wrapper around inspect.getdoc. This can't crash because of attribute problems. It also attempts to call a getdoc() method on the given object. This allows objects which provide their docstrings via non-standard mechanisms (like Pyro proxies) to still be inspected by ipython
(obj)
| 209 | |
| 210 | |
| 211 | def getdoc(obj) -> Union[str, None]: |
| 212 | """Stable wrapper around inspect.getdoc. |
| 213 | |
| 214 | This can't crash because of attribute problems. |
| 215 | |
| 216 | It also attempts to call a getdoc() method on the given object. This |
| 217 | allows objects which provide their docstrings via non-standard mechanisms |
| 218 | (like Pyro proxies) to still be inspected by ipython's ? system. |
| 219 | """ |
| 220 | # Allow objects to offer customized documentation via a getdoc method: |
| 221 | try: |
| 222 | ds = obj.getdoc() |
| 223 | except Exception: |
| 224 | pass |
| 225 | else: |
| 226 | if isinstance(ds, str): |
| 227 | return inspect.cleandoc(ds) |
| 228 | docstr = inspect.getdoc(obj) |
| 229 | return docstr |
| 230 | |
| 231 | |
| 232 | def getsource(obj, oname='') -> Union[str,None]: |