https://github.com/python/cpython/commit/977af3a6a21172b5ea73bd3fbf9eff5d6e813a73 commit: 977af3a6a21172b5ea73bd3fbf9eff5d6e813a73 branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: pablogsal <pablog...@gmail.com> date: 2025-03-10T22:18:13Z summary:
[3.13] gh-124927: Fix conversion issue between coordinates and position in REPL (GH-125001) (#131061) gh-124927: Fix conversion issue between coordinates and position in REPL (GH-125001) (cherry picked from commit 6ab5c4aa05bf35832a3ccd1e71b28b8475fa30f4) Co-authored-by: FeH2 <i...@feh2.im> files: A Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst M Lib/_pyrepl/reader.py M Lib/test/test_pyrepl/test_reader.py M Misc/ACKS diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index dc26bfd3a34ffb..68e2a9d4bd29e3 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -62,7 +62,7 @@ def disp_str(buffer: str) -> tuple[str, list[int]]: elif unicodedata.category(c).startswith("C"): c = r"\u%04x" % ord(c) s.append(c) - b.extend([0] * (len(c) - 1)) + b.append(len(c)) else: s.append(c) b.append(str_width(c)) @@ -577,6 +577,7 @@ def setpos_from_xy(self, x: int, y: int) -> None: cur_x = self.screeninfo[i][0] while cur_x < x: if self.screeninfo[i][1][j] == 0: + j += 1 # prevent potential future infinite loop continue cur_x += self.screeninfo[i][1][j] j += 1 diff --git a/Lib/test/test_pyrepl/test_reader.py b/Lib/test/test_pyrepl/test_reader.py index 27c6d6664eda9e..270d4d4fb8ae65 100644 --- a/Lib/test/test_pyrepl/test_reader.py +++ b/Lib/test/test_pyrepl/test_reader.py @@ -319,3 +319,11 @@ def test_pos2xy_with_no_columns(self): # Simulate a resize to 0 columns reader.screeninfo = [] self.assertEqual(reader.pos2xy(), (0, 0)) + + def test_setpos_from_xy_for_non_printing_char(self): + code = "# non \u200c printing character" + events = code_to_events(code) + + reader, _ = handle_all_events(events) + reader.setpos_from_xy(8, 0) + self.assertEqual(reader.pos, 7) diff --git a/Misc/ACKS b/Misc/ACKS index 54e6076773793b..b60ce58ca00114 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -277,6 +277,7 @@ Laurent De Buyst Zach Byrne Vedran Čačić Nicolas Cadou +Zhikai Cai Jp Calderone Ben Caller Arnaud Calmettes diff --git a/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst new file mode 100644 index 00000000000000..1fc485cd0527f0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst @@ -0,0 +1 @@ +Non-printing characters are now properly handled in the new REPL. _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com