gh-154470: Fix spurious ^J in pdb's colorized list command#154473
Conversation
pdb's `list` colorizes each source line with `_colorize_code`, which feeds it to `_pyrepl.utils.disp_str`. `disp_str` renders control characters in caret notation, so the trailing newline of each source line became a literal "^J". `_print_lines` only stripped the line *after* colorizing, and rstrip() cannot remove the embedded caret sequence. Strip the line before colorizing, matching what `where` already does via `format_stack_entry`. Add a test that attaches with colorize enabled, runs `list`, and asserts no "^J" leaks into the source lines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
I agree that the better way is to strip before colorize. However the is the test more complicated than it needs to be? We don't need remote pdb to trigger this issue - a local one would do. We missed it probably we normalized the white spaces in doctests? BTW I'm aware of this issue a while ago but did not get the time to fix it. Planned to fix before 3.15.0 official release. Sorry about that. |
|
Yeah, the failure existed on local pdb, too, but I opted for a remote test, because coloring happens on the remote end, so this additionally tests that this survives the client-server connection. Is it a big deal to have a remote test here? |
|
I think it's nice to have additional coverage for remote pdb, but we should probably have a quick and clean test for local pdb - it would be much easier to write and it targets the colorization with more focus. The remote pdb tests could potentially fail due to many other reasons. |
pdb's
listcolorizes each source line with_colorize_code, which feeds it to_pyrepl.utils.disp_str.disp_strrenders control characters in caret notation, so the trailing newline of each source line became a literal "^J"._print_linesonly stripped the line after colorizing, and rstrip() cannot remove the embedded caret sequence.Strip the line before colorizing, matching what
wherealready does viaformat_stack_entry. Add a test that attaches with colorize enabled, runslist, and asserts no "^J" leaks into the source lines.Broken by gh-146584.
listcommand output contains trailing ^J markers #154470