From 43ff8fcce21377cdce3a594ea10e1a045bb70752 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 21 Sep 2023 18:45:11 -0700 Subject: [PATCH] [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 68a6f21f47e779ddd70e33cf04d170a63f077fcd) Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com> --- Lib/pdb.py | 7 +++++-- Lib/test/test_pdb.py | 6 ++++++ Misc/ACKS | 1 + .../Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst diff --git a/Lib/pdb.py b/Lib/pdb.py index d3824e19fa8..fe9eab9b5e1 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -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:]) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 4f4a5692280..22fc2b35819 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -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() > (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 5fe93d63808..988c3675cf2 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -252,6 +252,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 00000000000..9b7a85d05f6 --- /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.