Skip to content
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

gh-123228: fix return type for _ReadlineWrapper.get_line_buffer() #123281

Merged
merged 7 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,14 @@ def add_history(self, line: str) -> None:
def set_startup_hook(self, function: Callback | None = None) -> None:
self.startup_hook = function

def get_line_buffer(self) -> bytes:
buf_str = self.get_reader().get_unicode()
return buf_str.encode(ENCODING)
def get_line_buffer(self) -> str:
return self.get_reader().get_unicode()

def _get_idxs(self) -> tuple[int, int]:
start = cursor = self.get_reader().pos
buf = self.get_line_buffer()
for i in range(cursor - 1, -1, -1):
if str(buf[i]) in self.get_completer_delims():
if buf[i] in self.get_completer_delims():
break
start = i
return start, cursor
Expand Down
8 changes: 7 additions & 1 deletion Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
make_clean_env,
)
from _pyrepl.console import Event
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
from _pyrepl.readline import (ReadlineAlikeReader, ReadlineConfig,
_ReadlineWrapper)
from _pyrepl.readline import multiline_input as readline_multiline_input

try:
Expand Down Expand Up @@ -516,6 +517,11 @@ def test_basic(self):
self.assertEqual(output, "1+1")
self.assertEqual(clean_screen(reader.screen), "1+1")

def test_get_line_buffer_returns_str(self):
reader = self.prepare_reader(code_to_events("\n"))
wrapper = _ReadlineWrapper(reader=reader)
self.assertIs(type(wrapper.get_line_buffer()), str)

def test_multiline_edit(self):
events = itertools.chain(
code_to_events("def f():\n...\n\n"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix return type for
:func:`!_pyrepl.readline._ReadlineWrapper.get_line_buffer` to be
:func:`str`. Patch by Sergey B Kirpichev.
Loading