[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 68a6f21f47)

Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2023-09-21 18:45:11 -07:00 committed by GitHub
parent 66a973a09e
commit 43ff8fcce2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 2 deletions

View file

@ -1505,8 +1505,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

@ -640,8 +640,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',
@ -650,8 +652,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

@ -252,6 +252,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.