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)
| 112 | return encoding |
| 113 | |
| 114 | def getdoc(obj) -> Union[str,None]: |
| 115 | """Stable wrapper around inspect.getdoc. |
| 116 | |
| 117 | This can't crash because of attribute problems. |
| 118 | |
| 119 | It also attempts to call a getdoc() method on the given object. This |
| 120 | allows objects which provide their docstrings via non-standard mechanisms |
| 121 | (like Pyro proxies) to still be inspected by ipython's ? system. |
| 122 | """ |
| 123 | # Allow objects to offer customized documentation via a getdoc method: |
| 124 | try: |
| 125 | ds = obj.getdoc() |
| 126 | except Exception: |
| 127 | pass |
| 128 | else: |
| 129 | if isinstance(ds, str): |
| 130 | return inspect.cleandoc(ds) |
| 131 | docstr = inspect.getdoc(obj) |
| 132 | return docstr |
| 133 | |
| 134 | |
| 135 | def getsource(obj, oname='') -> Union[str,None]: |