Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133349: Enable auto-indent for pdb's multi-line mode#133350

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gaogaotiantian merged 3 commits intopython:mainfromgaogaotiantian:pdb-auto-indent
May 5, 2025

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantiangaogaotiantian commentedMay 3, 2025
edited by bedevere-appbot
Loading

tanloong and shengbo-ma reacted with thumbs up emoji
@gaogaotiantian
Copy link
MemberAuthor

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.

@gaogaotiantian
Copy link
MemberAuthor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is indent always 4?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Up to you. This is fine.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's land this today and if people are complaining, we can treat that as a bug and fix it later :)

@gaogaotiantiangaogaotiantian merged commit0eeaa0e intopython:mainMay 5, 2025
43 checks passed
@gaogaotiantiangaogaotiantian deleted the pdb-auto-indent branchMay 5, 2025 17:48
nascheme pushed a commit to nascheme/cpython that referenced this pull requestMay 5, 2025
@vstinner
Copy link
Member

test_pdb.test_multiline_auto_indent() fails on FreeBSD:

FAIL: test_multiline_auto_indent (test.test_pdb.PdbTestReadline.test_multiline_auto_indent)----------------------------------------------------------------------Traceback (most recent call last):  File "/usr/home/vstinner/python/main/Lib/test/test_pdb.py", line 4870, in test_multiline_auto_indent    self.assertIn(b'42', output)    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^AssertionError: b'42' not found in bytearray(b"def f(x):\r\nif x > 0:\r\nx += 1\r\nreturn x\r\nelse:\r\nreturn -x\r\n\r\nf(-21-21)\r\nc\r\n> <string>(2)<module>()\r\n(Pdb) def f(x):\r\n...       if x > 0:\r\n...           x += 1\r\n...           return x\r\n...           else:\r\n*** SyntaxError: invalid syntax\r\n(Pdb) return -x\r\n*** Invalid argument: -x\r\n      Usage: r(eturn)\r\n(Pdb) \r\n*** Invalid argument: -x\r\n      Usage: r(eturn)\r\n(Pdb) f(-21-21)\r\n*** NameError: name \'f\' is not defined\r\n(Pdb) c\r\n")

Reformatted output (the bytearray):

"def f(x):\r\nif x > 0:\r\nx += 1\r\nreturn x\r\nelse:\r\nreturn -x\r\n\r\nf(-21-21)\r\nc\r\n> <string>(2)<module>()\r\n(Pdb) def f(x):\r\n...       if x > 0:\r\n...           x += 1\r\n...           return x\r\n...           else:\r\n*** SyntaxError: invalid syntax\r\n(Pdb) return -x\r\n*** Invalid argument: -x\r\n      Usage: r(eturn)\r\n(Pdb) \r\n*** Invalid argument: -x\r\n      Usage: r(eturn)\r\n(Pdb) f(-21-21)\r\n*** NameError: name \'f\' is not defined\r\n(Pdb) c\r\n"

And then test_multiline_indent_completion() hangs.

@gaogaotiantian
Copy link
MemberAuthor

I think the easy way is just to skip these tests on freebsd. This is a test issue, where freebsd does not consider\x08 a backspace. We might be able to find a character that actually works on freebsd, but I don't have a machine to test it out. It's a tier3 support so maybe we just let it go?

@vstinner
Copy link
Member

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.

@gaogaotiantian
Copy link
MemberAuthor

Could you try\x7f and see if that works?

@vstinner
Copy link
Member

Could you try \x7f and see if that works?

test_multiline_auto_indent() still fails if I replace \x08 with \x7f.

@vstinner
Copy link
Member

I wrote#133566 to skip the two tests on FreeBSD.

@tanloong
Copy link
Contributor

tanloong commentedMay 8, 2025
edited
Loading

freebsd does not consider\x08 a backspace

Just a remark, I tried and found that FreeBSD does interpret\x08 as backspace. The problem is that the auto-indented whitespaces are undeletable for some reason.

""" test-pdb-auto-indent.py """importtextwrapfromtest.support.pty_helperimportrun_ptyscript=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 += 1return xelse:           # fails to delete the auto-indented whitespaces:return -xf(-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 byrun_pty(). In a normal terminal (kitty+bash) it can't be reproduced, the auto-indented whitespaces are deletable by pressing backspaces.

simplescreenrecorder-2025-05-08_19.03.22.mp4

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@iritkatrieliritkatrieliritkatriel approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@gaogaotiantian@vstinner@tanloong@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp