Skip to content

Commit 775fd78

Browse files
[3.12] gh-109375: Fix bug where pdb registers an alias without an associated command (GH-109376) (#109429)
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 4b2ba3d commit 775fd78

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
@@ -1559,8 +1559,11 @@ def do_alias(self, arg):
15591559
for alias in keys:
15601560
self.message("%s = %s" % (alias, self.aliases[alias]))
15611561
return
1562-
if args[0] in self.aliases and len(args) == 1:
1563-
self.message("%s = %s" % (args[0], self.aliases[args[0]]))
1562+
if len(args) == 1:
1563+
if args[0] in self.aliases:
1564+
self.message("%s = %s" % (args[0], self.aliases[args[0]]))
1565+
else:
1566+
self.error(f"Unknown alias '{args[0]}'")
15641567
else:
15651568
self.aliases[args[0]] = ' '.join(args[1:])
15661569

Lib/test/test_pdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,10 @@ def test_pdb_alias_command():
662662
... o.method()
663663
664664
>>> with PdbTestInput([ # doctest: +ELLIPSIS
665+
... 'alias pi',
665666
... 'alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")',
666667
... 'alias ps pi self',
668+
... 'alias ps',
667669
... 'pi o',
668670
... 's',
669671
... 'ps',
@@ -672,8 +674,12 @@ def test_pdb_alias_command():
672674
... test_function()
673675
> <doctest test.test_pdb.test_pdb_alias_command[1]>(4)test_function()
674676
-> o.method()
677+
(Pdb) alias pi
678+
*** Unknown alias 'pi'
675679
(Pdb) alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")
676680
(Pdb) alias ps pi self
681+
(Pdb) alias ps
682+
ps = pi self
677683
(Pdb) pi o
678684
o.attr1 = 10
679685
o.attr2 = str

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ Curtis Bucher
254254
Colm Buckley
255255
Erik de Bueger
256256
Jan-Hein Bührman
257+
Marc Bürg
257258
Lars Buitinck
258259
Artem Bulgakov
259260
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)