Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,8 +1753,11 @@ def do_alias(self, arg):
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:])

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Curtis Bucher
Colm Buckley
Erik de Bueger
Jan-Hein Bührman
Marc Bürg
Lars Buitinck
Artem Bulgakov
Dick Bulterman
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :mod:`pdb` ``alias`` command now prevents registering aliases without arguments.