From 02e334fac300ea2a594d441e5e7898d1e3421788 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 24 Aug 2023 16:59:05 -0700 Subject: [PATCH 1/6] Make expressions work as expected in pdb --- Lib/pdb.py | 3 +++ Lib/test/test_pdb.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Lib/pdb.py b/Lib/pdb.py index 3db3e6a5be1a7b..671bc482e92e2b 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -231,6 +231,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, pass self.allow_kbdint = False self.nosigint = nosigint + # Consider these characters as part of the command so when the users type + # c.a or c['a'], it won't be recognized as a c(ontinue) command + self.identchars = cmd.Cmd.identchars + '.[]()"\'+-*/&|<>~^' # Read ~/.pdbrc and ./.pdbrc self.rcLines = [] diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index a66953557e52dc..0e4b6da04cceed 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1614,6 +1614,39 @@ def test_pdb_multiline_statement(): (Pdb) c """ +def test_pdb_show_attribute_and_item(): + """Test for multiline statement + + >>> def test_function(): + ... n = lambda x: x + ... c = {"a": 1} + ... j = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... pass + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'c["a"]', + ... 'c.get("a")', + ... 'n(1)', + ... 'j+1', + ... 'r"a"', + ... 'c' + ... ]): + ... test_function() + > (6)test_function() + -> pass + (Pdb) c["a"] + 1 + (Pdb) c.get("a") + 1 + (Pdb) n(1) + 1 + (Pdb) j+1 + 2 + (Pdb) r"a" + 'a' + (Pdb) c + """ def test_pdb_issue_20766(): """Test for reference leaks when the SIGINT handler is set. From 3c0a551f99e2de3ff1557cecf58554f25cec3582 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 24 Aug 2023 17:04:59 -0700 Subject: [PATCH 2/6] Add "=" for assignment --- Lib/pdb.py | 2 +- Lib/test/test_pdb.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 671bc482e92e2b..b5c172a16e9c2e 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -233,7 +233,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, self.nosigint = nosigint # Consider these characters as part of the command so when the users type # c.a or c['a'], it won't be recognized as a c(ontinue) command - self.identchars = cmd.Cmd.identchars + '.[]()"\'+-*/&|<>~^' + self.identchars = cmd.Cmd.identchars + '=.[]()"\'+-*/&|<>~^' # Read ~/.pdbrc and ./.pdbrc self.rcLines = [] diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 0e4b6da04cceed..b2bca1adcdcc94 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1620,7 +1620,6 @@ def test_pdb_show_attribute_and_item(): >>> def test_function(): ... n = lambda x: x ... c = {"a": 1} - ... j = 1 ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... pass @@ -1628,12 +1627,13 @@ def test_pdb_show_attribute_and_item(): ... 'c["a"]', ... 'c.get("a")', ... 'n(1)', + ... 'j=1', ... 'j+1', ... 'r"a"', ... 'c' ... ]): ... test_function() - > (6)test_function() + > (5)test_function() -> pass (Pdb) c["a"] 1 @@ -1641,6 +1641,7 @@ def test_pdb_show_attribute_and_item(): 1 (Pdb) n(1) 1 + (Pdb) j=1 (Pdb) j+1 2 (Pdb) r"a" From 03cd1ba35dc1f0e7f14e83597d4d94cff1c3bb83 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 00:14:36 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-08-25-00-14-34.gh-issue-108463.mQApp_.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-08-25-00-14-34.gh-issue-108463.mQApp_.rst diff --git a/Misc/NEWS.d/next/Library/2023-08-25-00-14-34.gh-issue-108463.mQApp_.rst b/Misc/NEWS.d/next/Library/2023-08-25-00-14-34.gh-issue-108463.mQApp_.rst new file mode 100644 index 00000000000000..a5ab8e2f9d4b59 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-08-25-00-14-34.gh-issue-108463.mQApp_.rst @@ -0,0 +1 @@ +Make expressions/statements work as expected in pdb From 5604e93a5dffb60975b49202eb591b1abfa31f88 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 1 Sep 2023 14:47:12 -0800 Subject: [PATCH 4/6] Add more characters to command list --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index b5c172a16e9c2e..239b95bb0f9474 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -233,7 +233,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, self.nosigint = nosigint # Consider these characters as part of the command so when the users type # c.a or c['a'], it won't be recognized as a c(ontinue) command - self.identchars = cmd.Cmd.identchars + '=.[]()"\'+-*/&|<>~^' + self.identchars = cmd.Cmd.identchars + '=.[](),"\'+-*/%@&|<>~^' # Read ~/.pdbrc and ./.pdbrc self.rcLines = [] From f603f1e367b0bf8ef2c96fa2888fb9de4b8ecbd9 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 4 Sep 2023 13:58:48 -0700 Subject: [PATCH 5/6] Add test cases for expr with full commands --- Lib/test/test_pdb.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index b2bca1adcdcc94..21f7ab1b41fe42 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1630,6 +1630,8 @@ def test_pdb_show_attribute_and_item(): ... 'j=1', ... 'j+1', ... 'r"a"', + ... 'next(iter([1]))', + ... 'list((0, 1))', ... 'c' ... ]): ... test_function() @@ -1646,6 +1648,10 @@ def test_pdb_show_attribute_and_item(): 2 (Pdb) r"a" 'a' + (Pdb) next(iter([1])) + 1 + (Pdb) list((0, 1)) + [0, 1] (Pdb) c """ From 37d17f4a3c028448b2fc966e494f912f575a87ed Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 4 Sep 2023 14:05:11 -0700 Subject: [PATCH 6/6] Add docs and what's new for the feature --- Doc/library/pdb.rst | 4 ++++ Doc/whatsnew/3.13.rst | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index ef52370bff8058..6d2375024d33bb 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -252,6 +252,10 @@ change a variable or call a function. When an exception occurs in such a statement, the exception name is printed but the debugger's state is not changed. +.. versionchanged:: 3.13 + Expressions/Statements whose prefix is a pdb command are now correctly + identified and executed. + The debugger supports :ref:`aliases `. Aliases can have parameters which allows one a certain level of adaptability to the context under examination. diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 4ff12b16d00266..1cfe38b3712daa 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -158,6 +158,13 @@ pathlib :meth:`~pathlib.Path.is_dir`. (Contributed by Barney Gale in :gh:`77609` and :gh:`105793`.) +pdb +--- + +* Expressions/Statements whose prefix is a pdb command are now correctly + identified and executed. + (Contributed by Tian Gao in :gh:`108464`.) + sqlite3 -------