gh-112510: Add `readline.backend` for the backend readline uses (GH-1… · Glyphack/cpython@3ce43cc · GitHub
Skip to content

Commit 3ce43cc

Browse files
gaogaotiantianblurb-it[bot]corona10
authored andcommitted
pythongh-112510: Add readline.backend for the backend readline uses (pythonGH-112511)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Donghee Na <donghee.na92@gmail.com>
1 parent 19e1561 commit 3ce43cc

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

Doc/library/readline.rst

Lines changed: 10 additions & 5 deletions

Lib/site.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ def register_readline():
444444

445445
# Reading the initialization (config) file may not be enough to set a
446446
# completion key, so we set one first and then read the file.
447-
readline_doc = getattr(readline, '__doc__', '')
448-
if readline_doc is not None and 'libedit' in readline_doc:
447+
if readline.backend == 'editline':
449448
readline.parse_and_bind('bind ^I rl_complete')
450449
else:
451450
readline.parse_and_bind('tab: complete')

Lib/test/test_pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3293,7 +3293,7 @@ def setUpClass():
32933293
# Ensure that the readline module is loaded
32943294
# If this fails, the test is skipped because SkipTest will be raised
32953295
readline = import_module('readline')
3296-
if readline.__doc__ and "libedit" in readline.__doc__:
3296+
if readline.backend == "editline":
32973297
raise unittest.SkipTest("libedit readline is not supported for pdb")
32983298

32993299
def test_basic_completion(self):

Lib/test/test_readline.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if hasattr(readline, "_READLINE_LIBRARY_VERSION"):
2020
is_editline = ("EditLine wrapper" in readline._READLINE_LIBRARY_VERSION)
2121
else:
22-
is_editline = (readline.__doc__ and "libedit" in readline.__doc__)
22+
is_editline = readline.backend == "editline"
2323

2424

2525
def setUpModule():
@@ -145,6 +145,9 @@ def test_init(self):
145145
TERM='xterm-256color')
146146
self.assertEqual(stdout, b'')
147147

148+
def test_backend(self):
149+
self.assertIn(readline.backend, ("readline", "editline"))
150+
148151
auto_history_script = """\
149152
import readline
150153
readline.set_auto_history({})
@@ -171,7 +174,7 @@ def complete(text, state):
171174
if state == 0 and text == "$":
172175
return "$complete"
173176
return None
174-
if "libedit" in getattr(readline, "__doc__", ""):
177+
if readline.backend == "editline":
175178
readline.parse_and_bind(r'bind "\\t" rl_complete')
176179
else:
177180
readline.parse_and_bind(r'"\\t": complete')
@@ -198,7 +201,7 @@ def test_nonascii(self):
198201

199202
script = r"""import readline
200203
201-
is_editline = readline.__doc__ and "libedit" in readline.__doc__
204+
is_editline = readline.backend == "editline"
202205
inserted = "[\xEFnserted]"
203206
macro = "|t\xEB[after]"
204207
set_pre_input_hook = getattr(readline, "set_pre_input_hook", None)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add :data:`readline.backend` for the backend readline uses (``editline`` or ``readline``)

Modules/readline.c

Lines changed: 8 additions & 1 deletion

0 commit comments

Comments
 (0)