gh-109375: Fix bug where pdb registers an alias without an associated command (#109376)

This commit is contained in:
buermarc 2023-09-14 23:31:30 +02:00 committed by GitHub
parent e091b9f20f
commit 68a6f21f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 2 deletions

View File

@ -1753,8 +1753,11 @@ class Pdb(bdb.Bdb, cmd.Cmd):
for alias in keys:
self.message("%s = %s" % (alias, self.aliases[alias]))
return
if args[0] in self.aliases and len(args) == 1:
self.message("%s = %s" % (args[0], self.aliases[args[0]]))
if len(args) == 1:
if args[0] in self.aliases:
self.message("%s = %s" % (args[0], self.aliases[args[0]]))
else:
self.error(f"Unknown alias '{args[0]}'")
else:
self.aliases[args[0]] = ' '.join(args[1:])

View File

@ -664,8 +664,10 @@ def test_pdb_alias_command():
... o.method()
>>> with PdbTestInput([ # doctest: +ELLIPSIS
... 'alias pi',
... 'alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")',
... 'alias ps pi self',
... 'alias ps',
... 'pi o',
... 's',
... 'ps',
@ -674,8 +676,12 @@ def test_pdb_alias_command():
... test_function()
> <doctest test.test_pdb.test_pdb_alias_command[1]>(4)test_function()
-> o.method()
(Pdb) alias pi
*** Unknown alias 'pi'
(Pdb) alias pi for k in %1.__dict__.keys(): print(f"%1.{k} = {%1.__dict__[k]}")
(Pdb) alias ps pi self
(Pdb) alias ps
ps = pi self
(Pdb) pi o
o.attr1 = 10
o.attr2 = str

View File

@ -254,6 +254,7 @@ Curtis Bucher
Colm Buckley
Erik de Bueger
Jan-Hein Bührman
Marc Bürg
Lars Buitinck
Artem Bulgakov
Dick Bulterman

View File

@ -0,0 +1 @@
The :mod:`pdb` ``alias`` command now prevents registering aliases without arguments.