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

Commitd8c118f

Browse files
authored
gh-133351: Fix remote PDB's multi-line block tab completion (#133387)
1 parent61b50a9 commitd8c118f

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

‎Lib/pdb.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,7 @@ def __init__(self, pid, sockfile, interrupt_script):
29332933
self.completion_matches= []
29342934
self.state="dumb"
29352935
self.write_failed=False
2936+
self.multiline_block=False
29362937

29372938
def_ensure_valid_message(self,msg):
29382939
# Ensure the message conforms to our protocol.
@@ -2979,6 +2980,7 @@ def _send(self, **kwargs):
29792980
self.write_failed=True
29802981

29812982
defread_command(self,prompt):
2983+
self.multiline_block=False
29822984
reply=input(prompt)
29832985

29842986
ifself.state=="dumb":
@@ -3003,6 +3005,7 @@ def read_command(self, prompt):
30033005
returnprefix+reply
30043006

30053007
# Otherwise, valid first line of a multi-line statement
3008+
self.multiline_block=True
30063009
continue_prompt="...".ljust(len(prompt))
30073010
whilecodeop.compile_command(reply,"<stdin>","single")isNone:
30083011
reply+="\n"+input(continue_prompt)
@@ -3105,9 +3108,13 @@ def complete(self, text, state):
31053108

31063109
origline=readline.get_line_buffer()
31073110
line=origline.lstrip()
3108-
stripped=len(origline)-len(line)
3109-
begidx=readline.get_begidx()-stripped
3110-
endidx=readline.get_endidx()-stripped
3111+
ifself.multiline_block:
3112+
# We're completing a line contained in a multi-line block.
3113+
# Force the remote to treat it as a Python expression.
3114+
line="! "+line
3115+
offset=len(origline)-len(line)
3116+
begidx=readline.get_begidx()-offset
3117+
endidx=readline.get_endidx()-offset
31113118

31123119
msg= {
31133120
"complete": {

‎Lib/test/test_remote_pdb.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,44 @@ def test_completion_in_pdb_state(self):
531531
expected_state={"state":"pdb"},
532532
)
533533

534+
deftest_multiline_completion_in_pdb_state(self):
535+
"""Test requesting tab completions at a (Pdb) continuation prompt."""
536+
# GIVEN
537+
incoming= [
538+
("server", {"prompt":"(Pdb) ","state":"pdb"}),
539+
("user", {"prompt":"(Pdb) ","input":"if True:"}),
540+
(
541+
"user",
542+
{
543+
"prompt":"... ",
544+
"completion_request": {
545+
"line":" b",
546+
"begidx":4,
547+
"endidx":5,
548+
},
549+
"input":" bool()",
550+
},
551+
),
552+
("server", {"completions": ["bin","bool","bytes"]}),
553+
("user", {"prompt":"... ","input":""}),
554+
]
555+
self.do_test(
556+
incoming=incoming,
557+
expected_outgoing=[
558+
{
559+
"complete": {
560+
"text":"b",
561+
"line":"! b",
562+
"begidx":2,
563+
"endidx":3,
564+
}
565+
},
566+
{"reply":"if True:\n bool()\n"},
567+
],
568+
expected_completions=["bin","bool","bytes"],
569+
expected_state={"state":"pdb"},
570+
)
571+
534572
deftest_completion_in_interact_state(self):
535573
"""Test requesting tab completions at a >>> prompt."""
536574
incoming= [
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix remote PDB to correctly request tab completions for Python expressions
2+
from the server when completing a continuation line of a multi-line Python
3+
block.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp