Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-118878: Pyrepl: show completions menu below the current line #118939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-118877: Fix AssertionError crash in pyrepl
A crash of the new pyrepl was triggered by
pressing up arrow when tab completion menu was displayed.
  • Loading branch information
danielhollas committed May 11, 2024
commit dc98b552a99e59cf1cf56e985d3c5d74942cd143
2 changes: 1 addition & 1 deletion 2 Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def do(self) -> None:
x, y = r.pos2xy()
new_y = y - 1

if new_y < 0:
if r.bol() == 0:
if r.historyi > 0:
r.select_item(r.historyi - 1)
return
Expand Down
25 changes: 24 additions & 1 deletion 25 Lib/test/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,30 @@ def test_global_namespace_completion(self):
output = multiline_input(reader, namespace)
self.assertEqual(output, "python")

def test_updown_arrow_with_completion_menu(self):
"""Up arrow in the middle of unfinished tab completion when the menu is displayed
should work and trigger going back in history. Down arrow should subsequently
get us back to the incomplete command."""
code = "import os\nos.\t\t"
namespace = {"os": os}

events = itertools.chain(
code_to_events(code),
[
Event(evt='key', data='up', raw=bytearray(b'\x1bOA')),
Event(evt="key", data="down", raw=bytearray(b"\x1bOB")),
],
code_to_events("\n")
)
reader = self.prepare_reader(events, namespace=namespace)
output = multiline_input(reader, namespace)
# This is the first line, nothing to see here
self.assertEqual(output, "import os")
# This is the second line. We pressed up and down arrows
# so we should end up where we were when we initiated tab completion.
output = multiline_input(reader, namespace)
self.assertEqual(output, "os.")


@patch("_pyrepl.curses.tigetstr", lambda x: b"")
class TestUnivEventQueue(TestCase):
Expand Down Expand Up @@ -1001,6 +1025,5 @@ def test_up_arrow_after_ctrl_r(self):
reader, _ = handle_all_events(events)
self.assert_screen_equals(reader, "")


if __name__ == '__main__':
unittest.main()
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.