From 447780204bc8297f64d79d99e92b49747f8021da Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 28 Jun 2021 17:01:50 +0100 Subject: [PATCH 1/3] bpo-44461: Fix bug with pdb's handling of import error due to a package which does not have a __main__ module --- Lib/bdb.py | 1 + Lib/pdb.py | 7 +++++-- Lib/test/test_pdb.py | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Lib/bdb.py b/Lib/bdb.py index 75d6113576372e..56ddfc2cf4756b 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -33,6 +33,7 @@ def __init__(self, skip=None): self.breaks = {} self.fncache = {} self.frame_returning = None + self.botframe = None self._load_breaks() diff --git a/Lib/pdb.py b/Lib/pdb.py index ff40f7b2476a38..4a255d618fa3a5 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1728,8 +1728,11 @@ def main(): print("Running 'cont' or 'step' will restart the program") t = sys.exc_info()[2] pdb.interaction(None, t) - print("Post mortem debugger finished. The " + mainpyfile + - " will be restarted") + if pdb._user_requested_quit: + break + else: + print("Post mortem debugger finished. The " + mainpyfile + + " will be restarted") # When invoked as main program, invoke the debugger on a script diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 0724b666a3bf8d..f8b52823be41ae 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1695,6 +1695,20 @@ def test_module_without_a_main(self): self.assertIn("ImportError: No module named t_main.__main__", stdout.splitlines()) + def test_package_without_a_main(self): + pkg_name = 't_pkg' + module_name = 't_main' + os_helper.rmtree(pkg_name) + modpath = pkg_name + '/' + module_name + os.makedirs(modpath) + with open(modpath + '/__init__.py', 'w') as f: + pass + self.addCleanup(os_helper.rmtree, pkg_name) + stdout, stderr = self._run_pdb(['-m', modpath.replace('/', '.')], "") + self.assertIn( + "'t_pkg.t_main' is a package and cannot be directly executed", + stdout) + def test_blocks_at_first_code_line(self): script = """ #This is a comment, on line 2 From 125a17caa4e87f888a62c3a0d90f9a9b5141fac2 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 29 Jun 2021 21:17:18 +0000 Subject: [PATCH 2/3] =?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 --- .../NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst diff --git a/Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst b/Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst new file mode 100644 index 00000000000000..02e25e928b9cff --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst @@ -0,0 +1 @@ +Fix bug with :mod:`pdb`'s handling of import error due to a package which does not have a ``__main__`` module \ No newline at end of file From 6acaeadd1499a6d7759abc78652786763af2ab5d Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Thu, 1 Jul 2021 12:01:46 +0100 Subject: [PATCH 3/3] remove "else" Co-authored-by: Jason R. Coombs --- Lib/pdb.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 4a255d618fa3a5..84102f8f50061c 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1730,9 +1730,8 @@ def main(): pdb.interaction(None, t) if pdb._user_requested_quit: break - else: - print("Post mortem debugger finished. The " + mainpyfile + - " will be restarted") + print("Post mortem debugger finished. The " + mainpyfile + + " will be restarted") # When invoked as main program, invoke the debugger on a script