Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-128067: Fix pyrepl overriding printed output without newlines#138732
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
074d743771b387011a7ca713b649edf20b7a43a3198c753453308891611a1f822e9542File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -183,8 +183,9 @@ def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None: | ||
| while len(self.screen) < min(len(screen), self.height): | ||
| self._hide_cursor() | ||
| self._move_relative(0, len(self.screen) - 1) | ||
| self.__write("\n") | ||
| if self.screen: | ||
| self._move_relative(0, len(self.screen) - 1) | ||
| self.__write("\n") | ||
| self.posxy = 0, len(self.screen) | ||
| self.screen.append("") | ||
| @@ -501,7 +502,7 @@ def clear(self) -> None: | ||
| """Wipe the screen""" | ||
| self.__write(CLEAR) | ||
| self.posxy = 0, 0 | ||
| self.screen = [""] | ||
| self.screen = [] | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "" here before was a clear attempt at working around the same issue that you're solving here, but I agree the In I'm okay with being defensive here, especially that this makes the behavior symmetrical between Windows and Unix. | ||
| def finish(self) -> None: | ||
| """Move the cursor to the end of the display and otherwise get | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1829,6 +1829,44 @@ def test_detect_pip_usage_in_repl(self): | ||
| ) | ||
| self.assertIn(hint, output) | ||
| @force_not_colorized | ||
| def test_no_newline(self): | ||
| env = os.environ.copy() | ||
| env.pop("PYTHON_BASIC_REPL", "") | ||
| env["PYTHON_BASIC_REPL"] = "1" | ||
| commands = "print('Something pretty long', end='')\nexit()\n" | ||
| expected_output_sequence = "Something pretty long>>> exit()" | ||
| basic_output, basic_exit_code = self.run_repl(commands, env=env) | ||
| self.assertEqual(basic_exit_code, 0) | ||
| self.assertIn(expected_output_sequence, basic_output) | ||
| output, exit_code = self.run_repl(commands) | ||
| self.assertEqual(exit_code, 0) | ||
| # Define escape sequences that don't affect cursor position or visual output | ||
| bracketed_paste_mode = r'\x1b\[\?2004[hl]' # Enable/disable bracketed paste | ||
| application_cursor_keys = r'\x1b\[\?1[hl]' # Enable/disable application cursor keys | ||
| application_keypad_mode = r'\x1b[=>]' # Enable/disable application keypad | ||
| insert_character = r'\x1b\[(?:1)?@(?=[ -~])' # Insert exactly 1 char (safe form) | ||
| cursor_visibility = r'\x1b\[\?25[hl]' # Show/hide cursor | ||
| cursor_blinking = r'\x1b\[\?12[hl]' # Start/stop cursor blinking | ||
| device_attributes = r'\x1b\[\?[01]c' # Device Attributes (DA) queries/responses | ||
chris-eibl marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| safe_escapes = re.compile( | ||
| f'{bracketed_paste_mode}|' | ||
| f'{application_cursor_keys}|' | ||
| f'{application_keypad_mode}|' | ||
| f'{insert_character}|' | ||
| f'{cursor_visibility}|' | ||
| f'{cursor_blinking}|' | ||
| f'{device_attributes}' | ||
| ) | ||
| cleaned_output = safe_escapes.sub('', output) | ||
| self.assertIn(expected_output_sequence, cleaned_output) | ||
| class TestPyReplCtrlD(TestCase): | ||
| """Test Ctrl+D behavior in _pyrepl to match old pre-3.13 REPL behavior. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix a bug in PyREPL on Windows where output without a trailing newline was overwritten by the next prompt. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spot on,
len(self.screen) - 1should not get negative here.