From 1393e3624b4831996a88366e944f37a4df898da5 Mon Sep 17 00:00:00 2001 From: Marc Buerg Date: Wed, 13 Sep 2023 16:18:16 +0200 Subject: [PATCH 1/4] gh-109375: Fix pdb alias command An unkown alias without a given command should not register a new alias. --- Lib/pdb.py | 2 ++ Lib/test/test_pdb.py | 6 ++++++ .../Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst | 1 + 3 files changed, 9 insertions(+) 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 e231d3d7eae475..536a703308d92f 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1755,6 +1755,8 @@ def do_alias(self, arg): return if args[0] in self.aliases and len(args) == 1: self.message("%s = %s" % (args[0], self.aliases[args[0]])) + elif len(args) == 1: + self.error("Unkown alias. To create an alias see 'help alias'") else: self.aliases[args[0]] = ' '.join(args[1:]) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index f337656121643c..6ad331c17bc902 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() > (4)test_function() -> o.method() + (Pdb) alias pi + *** Unkown alias. To create an alias see 'help alias' (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/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 00000000000000..3ed1ab889c852a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst @@ -0,0 +1 @@ +The pdb alias builtin now prevents registering aliases without a command. From 0fae8eb43c7c7631394e233c2fd3baaa5eed5ce7 Mon Sep 17 00:00:00 2001 From: buermarc <44375277+buermarc@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:09:44 +0200 Subject: [PATCH 2/4] Update Lib/pdb.py, Lib/test/test_pdb.py Co-authored-by: Tian Gao --- Lib/pdb.py | 9 +++++---- Lib/test/test_pdb.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 536a703308d92f..a391bc1df74d8e 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1753,10 +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]])) - elif len(args) == 1: - self.error("Unkown alias. To create an alias see 'help alias'") + 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 6ad331c17bc902..8fed1d0f7162fd 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -677,7 +677,7 @@ def test_pdb_alias_command(): > (4)test_function() -> o.method() (Pdb) alias pi - *** Unkown alias. To create an alias see 'help alias' + *** 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 From 94ff15c10e96ea48846a3c8790f9a3f922b8a33b Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Thu, 14 Sep 2023 20:12:22 +0100 Subject: [PATCH 3/4] tweak news --- .../next/Library/2023-09-13-17-22-44.gh-issue-109375.ijJHZ9.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 3ed1ab889c852a..9b7a85d05f66ca 100644 --- 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 @@ -1 +1 @@ -The pdb alias builtin now prevents registering aliases without a command. +The :mod:`pdb` ``alias`` command now prevents registering aliases without arguments. From 45adcb4e17bdbf7776fdda7340e2744ad22302c2 Mon Sep 17 00:00:00 2001 From: buermarc Date: Thu, 14 Sep 2023 21:21:36 +0200 Subject: [PATCH 4/4] Add name to Misc/ACKS --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index e52208a41cc9f7..fd3c68b58a180c 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