Render text documentation, given an object or a path to an object.
(thing, title='Python Library Documentation: %s', forceload=0,
renderer=None)
| 1710 | return thing, name if isinstance(name, str) else None |
| 1711 | |
| 1712 | def render_doc(thing, title='Python Library Documentation: %s', forceload=0, |
| 1713 | renderer=None): |
| 1714 | """Render text documentation, given an object or a path to an object.""" |
| 1715 | if renderer is None: |
| 1716 | renderer = text |
| 1717 | object, name = resolve(thing, forceload) |
| 1718 | desc = describe(object) |
| 1719 | module = inspect.getmodule(object) |
| 1720 | if name and '.' in name: |
| 1721 | desc += ' in ' + name[:name.rfind('.')] |
| 1722 | elif module and module is not object: |
| 1723 | desc += ' in module ' + module.__name__ |
| 1724 | |
| 1725 | if not (inspect.ismodule(object) or |
| 1726 | inspect.isclass(object) or |
| 1727 | inspect.isroutine(object) or |
| 1728 | inspect.isdatadescriptor(object) or |
| 1729 | _getdoc(object)): |
| 1730 | # If the passed object is a piece of data or an instance, |
| 1731 | # document its available methods instead of its value. |
| 1732 | if hasattr(object, '__origin__'): |
| 1733 | object = object.__origin__ |
| 1734 | else: |
| 1735 | object = type(object) |
| 1736 | desc += ' object' |
| 1737 | return title % desc + '\n\n' + renderer.document(object, name) |
| 1738 | |
| 1739 | def doc(thing, title='Python Library Documentation: %s', forceload=0, |
| 1740 | output=None, is_cli=False): |