]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109375: Fix bug where pdb registers an alias without an associated command (#109376)
authorbuermarc <44375277+buermarc@users.noreply.github.com>
Thu, 14 Sep 2023 21:31:30 +0000 (23:31 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Sep 2023 21:31:30 +0000 (22:31 +0100)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/ACKS
Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst [new file with mode: 0644]

index e231d3d7eae47588376290e8199e14592015a27a..a391bc1df74d8e76ed606481c4279390c1378ab6 100755 (executable)
@@ -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:])
 
index f337656121643c6424c3f58396cea56068ac5c3e..8fed1d0f7162fd4aff4b72835b3e39824d4dfe27 100644 (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
index e52208a41cc9f7da6468fc28b7797f340b25bbaa..fd3c68b58a180c64993850e548e935917e04da25 100644 (file)
--- 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 (file)
index 0000000..9b7a85d
--- /dev/null
@@ -0,0 +1 @@
+The :mod:`pdb` ``alias`` command now prevents registering aliases without arguments.