Skip to content

Commit 16ebb4c

Browse files
committed
Refactor code, reduce duplicate text.
1 parent 6020a53 commit 16ebb4c

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

Lib/pydoc.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,30 +1798,38 @@ def writedocs(dir, pkgpath='', done=None):
17981798
return
17991799

18001800

1801-
def _intro_basic():
1802-
# Intro text if basic REPL is used.
1801+
def _introdoc():
1802+
import textwrap
18031803
ver = '%d.%d' % sys.version_info[:2]
1804-
return f'''\
1805-
Welcome to Python {ver}'s help utility! If this is your first time using
1806-
Python, you should definitely check out the tutorial at
1807-
https://docs.python.org/{ver}/tutorial/.
1808-
1809-
Enter the name of any module, keyword, or topic to get help on writing
1810-
Python programs and using Python modules. To get a list of available
1811-
modules, keywords, symbols, or topics, enter "modules", "keywords",
1812-
"symbols", or "topics".
1813-
1814-
Each module also comes with a one-line summary of what it does; to list
1815-
the modules whose name or summary contain a given string such as "spam",
1816-
enter "modules spam".
1817-
1818-
To quit this help utility and return to the interpreter,
1819-
enter "q", "quit" or "exit".
1820-
'''
1804+
if os.environ.get('PYTHON_BASIC_REPL'):
1805+
pyrepl_keys = ''
1806+
else:
1807+
# Additional help for keyboard shortcuts if enhanced (non-basic) REPL is used.
1808+
pyrepl_keys = '''
1809+
You can use the following keyboard shortcuts at the main interpreter prompt.
1810+
F1: enter interactive help, F2: enter history browsing mode, F3: enter paste
1811+
mode (press again to exit).
1812+
'''
1813+
return textwrap.dedent(f'''\
1814+
Welcome to Python {ver}'s help utility! If this is your first time using
1815+
Python, you should definitely check out the tutorial at
1816+
https://docs.python.org/{ver}/tutorial/.
1817+
1818+
Enter the name of any module, keyword, or topic to get help on writing
1819+
Python programs and using Python modules. To get a list of available
1820+
modules, keywords, symbols, or topics, enter "modules", "keywords",
1821+
"symbols", or "topics".
1822+
{pyrepl_keys}
1823+
Each module also comes with a one-line summary of what it does; to list
1824+
the modules whose name or summary contain a given string such as "spam",
1825+
enter "modules spam".
1826+
1827+
To quit this help utility and return to the interpreter,
1828+
enter "q", "quit" or "exit".
1829+
''')
18211830

18221831

18231832
def _intro_pyrepl():
1824-
# Intro text if enhanced (non-basic) REPL is used.
18251833
ver = '%d.%d' % sys.version_info[:2]
18261834
return f'''
18271835
Welcome to Python {ver}'s help utility! If this is your first time using
@@ -2112,10 +2120,7 @@ def help(self, request, is_cli=False):
21122120
self.output.write('\n')
21132121

21142122
def intro(self):
2115-
if os.environ.get('PYTHON_BASIC_REPL'):
2116-
self.output.write(_intro_basic())
2117-
else:
2118-
self.output.write(_intro_pyrepl())
2123+
self.output.write(_introdoc())
21192124

21202125
def list(self, items, columns=4, width=80):
21212126
items = list(sorted(items))

0 commit comments

Comments
 (0)