Skip to content

gh-154470: Fix spurious ^J in pdb's colorized list command - #154473

Merged
gaogaotiantian merged 3 commits into
python:mainfrom
ambv:gh-154470-pdb-list-trailing-newline
Sep 15, 2026
Merged

gaogaotiantian merged 3 commits into
python:mainfrom
ambv:gh-154470-pdb-list-trailing-newline

Conversation

@ambv

@ambv ambv commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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.

Broken by gh-146584.

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>
@gaogaotiantian

Copy link
Copy Markdown
Member

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.

@ambv

ambv commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

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?

@gaogaotiantian

Copy link
Copy Markdown
Member

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.

@johnslavik

johnslavik commented Sep 8, 2026

Copy link
Copy Markdown
Member

I've fixed the conflicts.

we should probably have a quick and clean test for local pdb

on it

@johnslavik johnslavik added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 8, 2026
@johnslavik

Copy link
Copy Markdown
Member

@gaogaotiantian I think we can merge?

@gaogaotiantian

gaogaotiantian commented Sep 15, 2026

Copy link
Copy Markdown
Member

Yes, we don't need to block on testing. It's totally fine that we have a more sophisticated test from the remote side. We can add basic tests later.(did not see that you added the basic test) The source code fix is clean and nice, I'll just merge it.

@gaogaotiantian
gaogaotiantian merged commit c68ce16 into python:main Sep 15, 2026
57 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @ambv for the PR, and @gaogaotiantian for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Sep 15, 2026

Copy link
Copy Markdown

GH-157536 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 15, 2026
hugovk pushed a commit that referenced this pull request Sep 15, 2026
…-154473) (#157536)

gh-154470: Fix spurious ^J in pdb's colorized list command (GH-154473)
(cherry picked from commit c68ce16)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants