gh-133349: Enable auto-indent for pdb's multi-line mode#133350
gh-133349: Enable auto-indent for pdb's multi-line mode#133350gaogaotiantian merged 3 commits intopython:mainfrom
Conversation
|
Sorry for trying to squeeze this in 3.14 before beta freeze :) I think this should be pretty straightforward to review and it could help user experiences. |
|
Hey @iritkatriel , do you think we still have a chance to merge this before beta freeze? |
| last_line = last_line.rstrip('\r\n') | ||
| indent = len(last_line) - len(last_line.lstrip()) | ||
| if last_line.endswith(":"): | ||
| indent += 4 |
There was a problem hiding this comment.
We kind of dictated there, it is consistent with how we auto-fill the space when we hit <tab>. However, we can be smart and search for the history for the last indent. I have the time to do it and it should not be rocket science. Do you want me to do that?
There was a problem hiding this comment.
Let's land this today and if people are complaining, we can treat that as a bug and fix it later :)
|
test_pdb.test_multiline_auto_indent() fails on FreeBSD: Reformatted output (the bytearray): And then test_multiline_indent_completion() hangs. |
|
I think the easy way is just to skip these tests on freebsd. This is a test issue, where freebsd does not consider |
|
I have a FreeBSD machine, I can try some changes if you want. But if I have no clue why \x08 is not treated as backspace. I would also be fine with skipping the test on FreeBSD. |
|
Could you try |
test_multiline_auto_indent() still fails if I replace \x08 with \x7f. |
|
I wrote #133566 to skip the two tests on FreeBSD. |
Just a remark, I tried and found that FreeBSD does interpret """ test-pdb-auto-indent.py """
import textwrap
from test.support.pty_helper import run_pty
script = textwrap.dedent("""
import pdb; pdb.Pdb().set_trace()
""")
input = b"def g\x08f(x): # g is successfully deleted and replaced by f:\n"
input += b"if x > 0:\n"
input += b"x += 1\n"
input += b"return x\n"
input += b"\x08\x08\x08\x08else: # fails to delete the auto-indented whitespaces:\n"
input += b"return -x\n"
input += b"\n"
input += b"f(-21-21)\n"
input += b"c\n"
output = run_pty(script, input)
print(output)$ ./python ./test-pdb-auto-indent.py | sed -E 's/\\r\\n/\n/g'
bytearray(b"def g\x08 \x08f(x): # g is successfully deleted and replaced by f:
if x > 0:
x += 1
return x
else: # fails to delete the auto-indented whitespaces:
return -x
f(-21-21)
c
> <string>(2)<module>()
(Pdb) def f(x): # g is successfully deleted and replaced by f:
... if x > 0:
... x += 1
... return x
... else: # fails to delete the auto-indented whitespaces:
*** SyntaxError: invalid syntax
(Pdb) return -x
*** Invalid argument: -x
Usage: r(eturn)
(Pdb)
*** Invalid argument: -x
Usage: r(eturn)
(Pdb) f(-21-21)
*** NameError: name \'f\' is not defined
(Pdb) c
")The weird thing is that it happens only in the pseudo-terminal opened by simplescreenrecorder-2025-05-08_19.03.22.mp4 |
Uh oh!
There was an error while loading. Please reload this page.