MCPcopy Index your code
hub / github.com/python/cpython / showtopic

Method showtopic

Lib/pydoc.py:2113–2146  ·  view source on GitHub ↗
(self, topic, more_xrefs='')

Source from the content-addressed store, hash-verified

2111 self.list(self.topics.keys(), columns=3)
2112
2113 def showtopic(self, topic, more_xrefs=''):
2114 try:
2115 import pydoc_data.topics
2116 except ImportError:
2117 self.output.write('''
2118Sorry, topic and keyword documentation is not available because the
2119module "pydoc_data.topics" could not be found.
2120''')
2121 return
2122 target = self.topics.get(topic, self.keywords.get(topic))
2123 if not target:
2124 self.output.write('no documentation found for %s\n' % repr(topic))
2125 return
2126 if isinstance(target, str):
2127 return self.showtopic(target, more_xrefs)
2128
2129 label, xrefs = target
2130 try:
2131 doc = pydoc_data.topics.topics[label]
2132 except KeyError:
2133 self.output.write('no documentation found for %s\n' % repr(topic))
2134 return
2135 doc = doc.strip() + '\n'
2136 if more_xrefs:
2137 xrefs = (xrefs or '') + ' ' + more_xrefs
2138 if xrefs:
2139 text = 'Related help topics: ' + ', '.join(xrefs.split()) + '\n'
2140 wrapped_text = textwrap.wrap(text, 72)
2141 doc += '\n%s\n' % '\n'.join(wrapped_text)
2142
2143 if self._output is None:
2144 pager(doc, f'Help on {topic!s}')
2145 else:
2146 self.output.write(doc)
2147
2148 def _gettopic(self, topic, more_xrefs=''):
2149 """Return unbuffered tuple of (topic, xrefs).

Callers 6

helpMethod · 0.95
showsymbolMethod · 0.95
test_showtopicMethod · 0.95
test_fail_showtopicMethod · 0.95

Calls 7

pagerFunction · 0.85
writeMethod · 0.45
getMethod · 0.45
stripMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
wrapMethod · 0.45

Tested by 4

test_showtopicMethod · 0.76
test_fail_showtopicMethod · 0.76