]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-109375: Fix bug where pdb registers an alias without an associated command...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 Oct 2023 14:58:22 +0000 (07:58 -0700)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2023 14:58:22 +0000 (16:58 +0200)
gh-109375: Fix bug where pdb registers an alias without an associated command (GH-109376)
(cherry picked from commit 68a6f21f47e779ddd70e33cf04d170a63f077fcd)

Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com>
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 6b6feac1ddead14ab2158b3236f750e445c65158..646695ccd1f4dd8fcfa425ce0675a668f2cb26b6 100755 (executable)
@@ -1559,8 +1559,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 5793dbfbfdf4d074718408f4cb6699d9f1dead5f..c0fb61253be5ad75f53ea7dbe3dcc05f60269ffe 100644 (file)
@@ -662,8 +662,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',
@@ -672,8 +674,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 7deef8bad14a2c5ee65d812c1c7a7bb484e33856..5bba961158e6845ea8b82309d016336dfe0f8a7e 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.