[3.12] bpo-37755: Use configured output in pydoc instead of pager (GH-15105) (GH-120262)

If the Helper() class was initialized with an output, the topics, keywords
and symbols help still use the pager instead of the output.
Change the behavior so  the output is used if available while keeping the
previous behavior if no output was configured.
(cherry picked from commit 2080425154)

Co-authored-by: Enrico Tröger <enrico.troeger@uvena.de>
This commit is contained in:
Serhiy Storchaka 2024-06-08 12:46:25 +03:00 committed by GitHub
parent 479655a27a
commit 88f67df22c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 116 additions and 20 deletions

View file

@ -2148,7 +2148,7 @@ has the same effect as typing a particular string at the help> prompt.
elif request in self.symbols: self.showsymbol(request)
elif request in ['True', 'False', 'None']:
# special case these keywords since they are objects too
doc(eval(request), 'Help on %s:', is_cli=is_cli)
doc(eval(request), 'Help on %s:', output=self._output, is_cli=is_cli)
elif request in self.keywords: self.showtopic(request)
elif request in self.topics: self.showtopic(request)
elif request: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
@ -2241,7 +2241,11 @@ module "pydoc_data.topics" could not be found.
text = 'Related help topics: ' + ', '.join(xrefs.split()) + '\n'
wrapped_text = textwrap.wrap(text, 72)
doc += '\n%s\n' % '\n'.join(wrapped_text)
pager(doc)
if self._output is None:
pager(doc)
else:
self.output.write(doc)
def _gettopic(self, topic, more_xrefs=''):
"""Return unbuffered tuple of (topic, xrefs).