diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2023-09-04 21:44:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-04 21:44:40 (GMT) |
commit | 6304d983a0656c1841769bf36e5b42819508d21c (patch) | |
tree | c2434229a5d2c480b41e5a0b24b004c28a2218f7 | |
parent | 7855d325e638a4b7f7b40f2c35dc80de82d8fe70 (diff) | |
download | cpython-6304d983a0656c1841769bf36e5b42819508d21c.zip cpython-6304d983a0656c1841769bf36e5b42819508d21c.tar.gz cpython-6304d983a0656c1841769bf36e5b42819508d21c.tar.bz2 |
gh-108463: Make expressions/statements work as expected in pdb (#108464)
-rw-r--r-- | Doc/library/pdb.rst | 4 | ||||
-rw-r--r-- | Doc/whatsnew/3.13.rst | 4 | ||||
-rwxr-xr-x | Lib/pdb.py | 3 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 40 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-08-25-00-14-34.gh-issue-108463.mQApp_.rst | 1 |
5 files changed, 52 insertions, 0 deletions
diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 3aaac15..002eeef 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 <debugger-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 5d8ecbb..de23172 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -173,6 +173,10 @@ pdb the new ``exceptions [exc_number]`` command for Pdb. (Contributed by Matthias Bussonnier in :gh:`106676`.) +* Expressions/Statements whose prefix is a pdb command are now correctly + identified and executed. + (Contributed by Tian Gao in :gh:`108464`.) + sqlite3 ------- @@ -237,6 +237,9 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 734b5c8..a9edd1a 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1957,6 +1957,46 @@ 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} + ... 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', + ... 'j+1', + ... 'r"a"', + ... 'next(iter([1]))', + ... 'list((0, 1))', + ... 'c' + ... ]): + ... test_function() + > <doctest test.test_pdb.test_pdb_show_attribute_and_item[0]>(5)test_function() + -> pass + (Pdb) c["a"] + 1 + (Pdb) c.get("a") + 1 + (Pdb) n(1) + 1 + (Pdb) j=1 + (Pdb) j+1 + 2 + (Pdb) r"a" + 'a' + (Pdb) next(iter([1])) + 1 + (Pdb) list((0, 1)) + [0, 1] + (Pdb) c + """ def test_pdb_issue_20766(): """Test for reference leaks when the SIGINT handler is set. 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 0000000..a5ab8e2 --- /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 |