Resolve an object by dotted path from a module.
(module, path)
| 37 | |
| 38 | |
| 39 | def _resolve_object(module, path): |
| 40 | """Resolve an object by dotted path from a module.""" |
| 41 | if not path: |
| 42 | return module, None, module.__name__ |
| 43 | |
| 44 | parts = path.split(".") |
| 45 | parent = None |
| 46 | obj = module |
| 47 | |
| 48 | for part in parts: |
| 49 | parent = obj |
| 50 | try: |
| 51 | obj = getattr(obj, part) |
| 52 | except AttributeError: |
| 53 | try: |
| 54 | obj = vars(parent).get(part) |
| 55 | if obj is not None: |
| 56 | continue |
| 57 | except TypeError: |
| 58 | pass |
| 59 | return None, None, None |
| 60 | |
| 61 | return obj, parent, getattr(obj, "__name__", parts[-1]) |
| 62 | |
| 63 | |
| 64 | def _get_docstring(name, module, indentation): |