From a326c24f6949a96e63b5f7912d892f0e7c8fbbe6 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 29 Mar 2023 23:32:41 -0700 Subject: [PATCH 1/4] Draft for pdb multiline support --- Lib/pdb.py | 26 +++++++++++++++++++++++++- Lib/test/test_pdb.py | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 3a06cd00ad2bf1..932173dff18ba8 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -76,6 +76,7 @@ import dis import code import glob +import codeop import pprint import signal import inspect @@ -438,7 +439,30 @@ def default(self, line): locals = self.curframe_locals globals = self.curframe.f_globals try: - code = compile(line + '\n', '', 'single') + if (code := codeop.compile_command(line + '\n', '', 'single')) is None: + # Multi-line mode + buffer = line + continue_prompt = "... " + while (code := codeop.compile_command(buffer, '', 'single')) is None: + if self.use_rawinput: + try: + line = input(continue_prompt) + except (EOFError, KeyboardInterrupt): + self.lastcmd = "" + print('\n') + return + else: + self.stdout.write(continue_prompt) + self.stdout.flush() + line = self.stdin.readline() + if not len(line): + self.lastcmd = "" + self.stdout.write('\n') + self.stdout.flush() + return + else: + line = line.rstrip('\r\n') + buffer += '\n' + line save_stdout = sys.stdout save_stdin = sys.stdin save_displayhook = sys.displayhook diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index de2bab46495729..6edfe76edb86fb 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -387,7 +387,7 @@ def test_pdb_breakpoints_preserved_across_interactive_sessions(): 1 breakpoint keep yes at ...test_pdb.py:... 2 breakpoint keep yes at ...test_pdb.py:... (Pdb) break pdb.find_function - Breakpoint 3 at ...pdb.py:97 + Breakpoint 3 at ...pdb.py:98 (Pdb) break Num Type Disp Enb Where 1 breakpoint keep yes at ...test_pdb.py:... From 3684e3ab2c94d86f340f5a4cd3b5bf8a6df3861c Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 29 Mar 2023 23:41:14 -0700 Subject: [PATCH 2/4] Do not use actual line number for the test --- Lib/test/test_pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 6edfe76edb86fb..8f112050da5462 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -387,7 +387,7 @@ def test_pdb_breakpoints_preserved_across_interactive_sessions(): 1 breakpoint keep yes at ...test_pdb.py:... 2 breakpoint keep yes at ...test_pdb.py:... (Pdb) break pdb.find_function - Breakpoint 3 at ...pdb.py:98 + Breakpoint 3 at ...pdb.py:... (Pdb) break Num Type Disp Enb Where 1 breakpoint keep yes at ...test_pdb.py:... From 2dcfce79a8fd12068be830011dfdaf99bdd2bf7b Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 8 Apr 2023 20:52:04 -0700 Subject: [PATCH 3/4] Add test for multiline statement --- Lib/test/test_pdb.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 8f112050da5462..bf9df505b41e90 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1481,6 +1481,32 @@ def test_pdb_next_command_subiterator(): (Pdb) continue """ +def test_pdb_multiline_statement(): + """Test for multiline statement + + >>> def test_function(): + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... pass + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'def f(x):', + ... ' return x * 2', + ... '', + ... 'f(2)', + ... 'c' + ... ]): + ... test_function() + > (3)test_function() + -> pass + (Pdb) def f(x): + ... return x * 2 + ... + (Pdb) f(2) + 4 + (Pdb) c + """ + + def test_pdb_issue_20766(): """Test for reference leaks when the SIGINT handler is set. @@ -2185,7 +2211,7 @@ def test_relative_imports_on_plain_module(self): def test_errors_in_command(self): commands = "\n".join([ - 'print(', + 'print(]', 'debug print(', 'debug doesnotexist', 'c', @@ -2194,7 +2220,8 @@ def test_errors_in_command(self): self.assertEqual(stdout.splitlines()[1:], [ '-> pass', - '(Pdb) *** SyntaxError: \'(\' was never closed', + "(Pdb) *** SyntaxError: closing parenthesis ']' does not match opening " + "parenthesis '('", '(Pdb) ENTERING RECURSIVE DEBUGGER', '*** SyntaxError: \'(\' was never closed', From 5aeb19da8ebb9970f7abbdb581c1233244564c13 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 9 Apr 2023 03:53:03 +0000 Subject: [PATCH 4/4] =?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-04-09-03-53-02.gh-issue-103124.JspiNN.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-04-09-03-53-02.gh-issue-103124.JspiNN.rst diff --git a/Misc/NEWS.d/next/Library/2023-04-09-03-53-02.gh-issue-103124.JspiNN.rst b/Misc/NEWS.d/next/Library/2023-04-09-03-53-02.gh-issue-103124.JspiNN.rst new file mode 100644 index 00000000000000..022524b369aa10 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-09-03-53-02.gh-issue-103124.JspiNN.rst @@ -0,0 +1 @@ +Added multiline statement support for :mod:`pdb` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy