summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbuermarc <44375277+buermarc@users.noreply.github.com>2023-09-14 21:31:30 (GMT)
committerGitHub <noreply@github.com>2023-09-14 21:31:30 (GMT)
commit68a6f21f47e779ddd70e33cf04d170a63f077fcd (patch)
tree099ce16f9e32777961999232aa5de8879800624c
parente091b9f20fa8e409003af79f3c468b8225e6dcd3 (diff)
downloadcpython-68a6f21f47e779ddd70e33cf04d170a63f077fcd.zip
cpython-68a6f21f47e779ddd70e33cf04d170a63f077fcd.tar.gz
cpython-68a6f21f47e779ddd70e33cf04d170a63f077fcd.tar.bz2
gh-109375: Fix bug where pdb registers an alias without an associated command (#109376)
-rwxr-xr-xLib/pdb.py7
-rw-r--r--Lib/test/test_pdb.py6
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst1
4 files changed, 13 insertions, 2 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index e231d3d..a391bc1 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -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:])
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index f337656..8fed1d0 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -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
diff --git a/Misc/ACKS b/Misc/ACKS
index e52208a..fd3c68b 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -254,6 +254,7 @@ Curtis Bucher
Colm Buckley
Erik de Bueger
Jan-Hein Bührman
+Marc Bürg
Lars Buitinck
Artem Bulgakov
Dick Bulterman
diff --git a/Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst b/Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst
new file mode 100644
index 0000000..9b7a85d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst
@@ -0,0 +1 @@
+The :mod:`pdb` ``alias`` command now prevents registering aliases without arguments.