gh-153902: strip trailing newlines when displaying source in pdb#153905
gh-153902: strip trailing newlines when displaying source in pdb#153905saucoide wants to merge 3 commits into
Conversation
The source lines pdb fetches from linecache.getlines & inspect.getsourcelines have trailing `\n` characters, passing them to _pyrepl.utils.disp_str turns them into `^J` codes dirtying the output pdb already prints line by line with end="\n" so rstripping each line shouldnt change the output
| s += '>>' | ||
| if self.colorize: | ||
| line = self._colorize_code(line) | ||
| line = self._colorize_code(line.rstrip()) |
There was a problem hiding this comment.
I agree that this is probably something pyrepl should fix. It should not just render \n to ^J unconditionally. Let's see if they'll fix that. If not, pdb can make its mitigation.
There was a problem hiding this comment.
I think the pyrepl change can be made in this PR, it's not a bug in the pyrepl's use-case.
There was a problem hiding this comment.
that does look better, @StanFromIreland do you know if hugo's change is going to be merged and this should wait for it, or we bring the change here?
There was a problem hiding this comment.
Hugo’s change probably won’t be merged for a while, so we can do it here first.
CC @hugovk
There was a problem hiding this comment.
brought the commit & updated this one
|
I don't like this approach for this particular fix. Note that pdb already r-strips the line, only it does it after the colorizing. So a surgical fix is to just move the stripping pre-colorization. It's what I did in gh-154473 where I also focused on the more important piece of a PR like this: how to test this doesn't regress in the future. Closing this PR, given that @hugovk's _pyrepl utils feature can (and will) be merged separately anyway. |
The source lines pdb fetches from
linecache.getlines&inspect.getsourcelineshave trailing\ncharacterspassing them to _pyrepl.utils.disp_str turns them into
^Jcodes dirtying the output, pdb already prints line by line withend="\n"so rstripping each line shouldnt change the outputMaybe there is already a plan to whole switch pdb's output to the use the structured renderer from pyrepl, but in the meantime it looks broken
landllcommands print raw ansi codes for every new line #153902