Skip to content

Commit 986bc7c

Browse files
committed
gh-130472: Show PyREPL completion menus left to right
1 parent a7f83bd commit 986bc7c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Lib/_pyrepl/readline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ReadlineAlikeReader(historical_reader.HistoricalReader, CompletingReader):
110110
# Class fields
111111
assume_immutable_completions = False
112112
use_brackets = False
113-
sort_in_column = True
113+
sort_in_column = False
114114

115115
# Instance fields
116116
config: ReadlineConfig

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,39 @@ class Obj:
10001000
self.assertNotIn("banana", menu)
10011001
self.assertNotIn("mro", menu)
10021002

1003+
def test_completion_menu_is_sorted_left_to_right(self):
1004+
namespace = {
1005+
"Py_AAA": 1,
1006+
"Py_BBB": 1,
1007+
"Py_CompileString": 1,
1008+
"Py_FatalError": 1,
1009+
"Py_Finalize": 1,
1010+
"Py_Initialize": 1,
1011+
"Py_IsInitialized": 1,
1012+
"Py_ZZZ": 1,
1013+
}
1014+
console = FakeConsole(code_to_events("Py_\t\t"))
1015+
console.width = 40
1016+
config = ReadlineConfig()
1017+
config.readline_completer = FancyCompleter(
1018+
namespace, use_colors=True
1019+
).complete
1020+
reader = ReadlineAlikeReader(console=console, config=config)
1021+
1022+
with self.assertRaises(StopIteration):
1023+
while True:
1024+
reader.handle1()
1025+
1026+
self.assertEqual(
1027+
[stripcolor(row).rstrip() for row in reader.cmpltn_menu],
1028+
[
1029+
"Py_AAA Py_BBB",
1030+
"Py_CompileString Py_FatalError",
1031+
"Py_Finalize Py_Initialize",
1032+
"Py_IsInitialized Py_ZZZ",
1033+
],
1034+
)
1035+
10031036
def test_get_completions_sorts_colored_matches_by_visible_text(self):
10041037
console = FakeConsole(iter(()))
10051038
config = ReadlineConfig()

0 commit comments

Comments
 (0)