Skip to content

Commit 43ff8fc

Browse files
[3.11] gh-109375: Fix bug where pdb registers an alias without an associated command (GH-109376) (#109430)
gh-109375: Fix bug where pdb registers an alias without an associated command (GH-109376) (cherry picked from commit 68a6f21) Co-authored-by: buermarc <[email protected]>
1 parent 66a973a commit 43ff8fc

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

Lib/pdb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,8 +1505,11 @@ def do_alias(self, arg):
15051505
for alias in keys:
15061506
self.message("%s = %s" % (alias, self.aliases[alias]))
15071507
return
1508-
if args[0] in self.aliases and len(args) == 1:
1509-
self.message("%s = %s" % (args[0], self.aliases[args[0]]))
1508+
if len(args) == 1:
1509+
if args[0] in self.aliases:
1510+
self.message("%s = %s" % (args[0], self.aliases[args[0]]))
1511+
else:
1512+
self.error(f"Unknown alias '{args[0]}'")
15101513
else:
15111514
self.aliases[args[0]] = ' '.join(args[1:])
15121515

Lib/test/test_pdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,10 @@ def test_pdb_alias_command():
640640
... o.method()
641641
642642
>>> with PdbTestInput([ # doctest: +ELLIPSIS
643+
... 'alias pi',
643644
... 'alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")',
644645
... 'alias ps pi self',
646+
... 'alias ps',
645647
... 'pi o',
646648
... 's',
647649
... 'ps',
@@ -650,8 +652,12 @@ def test_pdb_alias_command():
650652
... test_function()
651653
> <doctest test.test_pdb.test_pdb_alias_command[1]>(4)test_function()
652654
-> o.method()
655+
(Pdb) alias pi
656+
*** Unknown alias 'pi'
653657
(Pdb) alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")
654658
(Pdb) alias ps pi self
659+
(Pdb) alias ps
660+
ps = pi self
655661
(Pdb) pi o
656662
o.attr1 = 10
657663
o.attr2 = str

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ Curtis Bucher
252252
Colm Buckley
253253
Erik de Bueger
254254
Jan-Hein Bührman
255+
Marc Bürg
255256
Lars Buitinck
256257
Artem Bulgakov
257258
Dick Bulterman
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :mod:`pdb` ``alias`` command now prevents registering aliases without arguments.

0 commit comments

Comments
 (0)