Render text documentation, given an object or a path to an object.
(thing, title='Python Library Documentation: %s', forceload=0,
renderer=None)
| 1756 | return thing, name if isinstance(name, str) else None |
| 1757 | |
| 1758 | def render_doc(thing, title='Python Library Documentation: %s', forceload=0, |
| 1759 | renderer=None): |
| 1760 | """Render text documentation, given an object or a path to an object.""" |
| 1761 | if renderer is None: |
| 1762 | renderer = text |
| 1763 | object, name = resolve(thing, forceload) |
| 1764 | desc = describe(object) |
| 1765 | module = inspect.getmodule(object) |
| 1766 | if name and '.' in name: |
| 1767 | desc += ' in ' + name[:name.rfind('.')] |
| 1768 | elif module and module is not object: |
| 1769 | desc += ' in module ' + module.__name__ |
| 1770 | |
| 1771 | if not (inspect.ismodule(object) or |
| 1772 | inspect.isclass(object) or |
| 1773 | inspect.isroutine(object) or |
| 1774 | inspect.isdatadescriptor(object) or |
| 1775 | _getdoc(object)): |
| 1776 | # If the passed object is a piece of data or an instance, |
| 1777 | # document its available methods instead of its value. |
| 1778 | if hasattr(object, '__origin__'): |
| 1779 | object = object.__origin__ |
| 1780 | else: |
| 1781 | object = type(object) |
| 1782 | desc += ' object' |
| 1783 | return title % desc + '\n\n' + renderer.document(object, name) |
| 1784 | |
| 1785 | def doc(thing, title='Python Library Documentation: %s', forceload=0, |
| 1786 | output=None, is_cli=False): |