Produce a short description of the given thing.
(thing)
| 1768 | sys.stdout.write(plain(_escape_stdout(text))) |
| 1769 | |
| 1770 | def describe(thing): |
| 1771 | """Produce a short description of the given thing.""" |
| 1772 | if inspect.ismodule(thing): |
| 1773 | if thing.__name__ in sys.builtin_module_names: |
| 1774 | return 'built-in module ' + thing.__name__ |
| 1775 | if hasattr(thing, '__path__'): |
| 1776 | return 'package ' + thing.__name__ |
| 1777 | else: |
| 1778 | return 'module ' + thing.__name__ |
| 1779 | if inspect.isbuiltin(thing): |
| 1780 | return 'built-in function ' + thing.__name__ |
| 1781 | if inspect.isgetsetdescriptor(thing): |
| 1782 | return 'getset descriptor %s.%s.%s' % ( |
| 1783 | thing.__objclass__.__module__, thing.__objclass__.__name__, |
| 1784 | thing.__name__) |
| 1785 | if inspect.ismemberdescriptor(thing): |
| 1786 | return 'member descriptor %s.%s.%s' % ( |
| 1787 | thing.__objclass__.__module__, thing.__objclass__.__name__, |
| 1788 | thing.__name__) |
| 1789 | if inspect.isclass(thing): |
| 1790 | return 'class ' + thing.__name__ |
| 1791 | if inspect.isfunction(thing): |
| 1792 | return 'function ' + thing.__name__ |
| 1793 | if inspect.ismethod(thing): |
| 1794 | return 'method ' + thing.__name__ |
| 1795 | return type(thing).__name__ |
| 1796 | |
| 1797 | def locate(path, forceload=0): |
| 1798 | """Locate an object by name or dotted path, importing as necessary.""" |
no test coverage detected