Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

gh-133400: Fixed Ctrl+D (^D) behavior in :mod:_pyrepl module#133883

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
deepwzh wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromdeepwzh:fix-issue-133400
Open
Show file tree
Hide file tree
Changes fromall commits
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
3 changes: 3 additions & 0 deletionsLib/_pyrepl/commands.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -421,6 +421,9 @@ def do(self) -> None:
r.update_screen()
r.console.finish()
raise EOFError
elif "\n" in b and self.event[-1] == "\004":
self.finish = True

for i in range(r.get_arg()):
if r.pos != len(b):
del b[r.pos]
Expand Down
40 changes: 40 additions & 0 deletionsLib/test/test_pyrepl/test_pyrepl.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1610,3 +1610,43 @@ def test_prompt_after_help(self):
# Extra stuff (newline and `exit` rewrites) are necessary
# because of how run_repl works.
self.assertNotIn(">>> \n>>> >>>", cleaned_output)

class TestPyReplCtrlD(TestCase):
def prepare_reader(self, events):
console = FakeConsole(events)
config = ReadlineConfig(readline_completer=None)
reader = ReadlineAlikeReader(console=console, config=config)
return reader

def test_ctrl_d_empty_buffer(self):
"""Test that pressing Ctrl+D on empty buffer exits the program"""
events = [
Event(evt="key", data="\x04", raw=bytearray(b"\x04")), # Ctrl+D
]
reader = self.prepare_reader(events)
with self.assertRaises(EOFError):
multiline_input(reader)

def test_ctrl_d_multiline_mode(self):
"""Test that pressing Ctrl+D in multiline mode exits multiline mode"""
events = itertools.chain(
code_to_events("def f():\n"), # Enter multiline mode
[
Event(evt="key", data="\x04", raw=bytearray(b"\x04")), # Ctrl+D
],
)
reader = self.prepare_reader(events)
output = multiline_input(reader)
self.assertEqual(output, "def f():\n ") # Should return current input

def test_ctrl_d_single_line(self):
"""Test that pressing Ctrl+D in single line mode deletes current character"""
events = itertools.chain(
code_to_events("hello"),
[Event(evt="key", data="left", raw=bytearray(b"\x1bOD"))], # move left
[Event(evt="key", data="\x04", raw=bytearray(b"\x04"))], # Ctrl+D
code_to_events("\n"),
)
reader = self.prepare_reader(events)
output = multiline_input(reader)
self.assertEqual(output, "hell") # Should delete the last character
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fixed Ctrl+D (^D) behavior in _pyrepl module: Now properly exits multiline
mode when pressed in multiline section. Added test cases to verify the
behavior in both multiline and single line modes.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp