From c91afc1c0a7b5ba780e960ca495f1b064d410fb5 Mon Sep 17 00:00:00 2001 From: James Gerity Date: Fri, 10 Jun 2022 16:23:40 -0400 Subject: [PATCH 1/8] Locate frozen module source with __file__ --- Lib/pdb.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/pdb.py b/Lib/pdb.py index e6ed814acbe19a..f66cb5ca8b6200 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1332,6 +1332,10 @@ def do_list(self, arg): if last is None: last = first + 10 filename = self.curframe.f_code.co_filename + # gh-93696: stdlib frozen modules provide a useful __file__ (see also gh-89815) + if filename.startswith(" Date: Fri, 10 Jun 2022 16:38:08 -0400 Subject: [PATCH 2/8] Add NEWS entry --- .../2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst new file mode 100644 index 00000000000000..17ea07b1f706ce --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst @@ -0,0 +1 @@ +Allow ``pdb`` to locate source for frozen modules in the standard library. From ff51687a521c252f5b7737ad2688e88efc493277 Mon Sep 17 00:00:00 2001 From: James Gerity Date: Sun, 12 Jun 2022 18:09:31 -0400 Subject: [PATCH 3/8] Add test for listing source for frozen modules --- Lib/test/test_pdb.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 0141b739c25440..d0105ebe7ac2e0 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1963,6 +1963,52 @@ def test_issue42383(self): expected = '(Pdb) The correct file was executed' self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected) + def test_frozen_list(self): + frozen_src = """ + def func(): + x = "Sentinel string for gh-93696" + print(x) + """ + host_program = """ + import os + import sys + + def _create_fake_frozen_module(): + with open('gh93696.py') as f: + src = f.read() + + # this function has a co_filename as if it were in a frozen module + dummy_mod = compile(src, "", "exec") + func_code = dummy_mod.co_consts[0] + + mod = type(sys)("gh93696") + mod.func = type(lambda: None)(func_code, mod.__dict__) + mod.__file__ = 'gh93696.py' + + return mod + + mod = _create_fake_frozen_module() + mod.func() + """ + commands = """ + break 20 + continue + step + list + quit + """ + with open('gh93696.py', 'w') as f: + f.write(textwrap.dedent(frozen_src)) + + with open('gh93696_host.py', 'w') as f: + f.write(textwrap.dedent(host_program)) + + self.addCleanup(os_helper.unlink, 'gh93696.py') + self.addCleanup(os_helper.unlink, 'gh93696_host.py') + stdout, stderr = self._run_pdb(["gh93696_host.py"], commands) + # verify that pdb found the source of the "frozen" function + self.assertTrue('x = "Sentinel string for gh-93696"' in stdout, "Sentinel statement not found") + class ChecklineTests(unittest.TestCase): def setUp(self): From e88d3a5e30d7aeedfad32f5dc6e8f9ffd00d9ed2 Mon Sep 17 00:00:00 2001 From: James Gerity Date: Fri, 15 Jul 2022 14:25:28 -0400 Subject: [PATCH 4/8] Add issue reference to frozen_list 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 bceae2e7f18d55..63d45cfebfdf6c 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2104,7 +2104,7 @@ def inner(v): pass stdout, stderr = self.run_pdb_script(script, commands) self.assertFalse(stderr) - def test_frozen_list(self): + def test_gh_93696_frozen_list(self): frozen_src = """ def func(): x = "Sentinel string for gh-93696" From 116c26be2a231ca9380757fd893d13fdc9475dae Mon Sep 17 00:00:00 2001 From: James Gerity Date: Sun, 17 Jul 2022 14:37:26 -0400 Subject: [PATCH 5/8] Use assertIn() instead of assertTrue() Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- 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 63d45cfebfdf6c..48f419e62fbbed 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2148,7 +2148,7 @@ def _create_fake_frozen_module(): self.addCleanup(os_helper.unlink, 'gh93696_host.py') stdout, stderr = self._run_pdb(["gh93696_host.py"], commands) # verify that pdb found the source of the "frozen" function - self.assertTrue('x = "Sentinel string for gh-93696"' in stdout, "Sentinel statement not found") + self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found") class ChecklineTests(unittest.TestCase): def setUp(self): From 163f3df2c0e9406ce10ae1f040da2df82d5a99e6 Mon Sep 17 00:00:00 2001 From: James Gerity Date: Sun, 17 Jul 2022 14:38:08 -0400 Subject: [PATCH 6/8] Link to pdb module docs in news fragment Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- .../2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst index 17ea07b1f706ce..8eadab0ad8fb78 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-10-16-37-44.gh-issue-93696.65BI2R.rst @@ -1 +1 @@ -Allow ``pdb`` to locate source for frozen modules in the standard library. +Allow :mod:`pdb` to locate source for frozen modules in the standard library. From 55f2a0f0b317bec41196b7acaa6b717fc72ca57f Mon Sep 17 00:00:00 2001 From: James Gerity Date: Fri, 22 Jul 2022 14:29:23 -0400 Subject: [PATCH 7/8] Clarify that gh-89815 is a superceding issue --- Lib/pdb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index f66cb5ca8b6200..439a4d1913a477 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1332,7 +1332,8 @@ def do_list(self, arg): if last is None: last = first + 10 filename = self.curframe.f_code.co_filename - # gh-93696: stdlib frozen modules provide a useful __file__ (see also gh-89815) + # gh-93696: stdlib frozen modules provide a useful __file__ + # this workaround can be removed with the closure of gh-89815 if filename.startswith(" Date: Tue, 25 Oct 2022 01:06:15 -0400 Subject: [PATCH 8/8] Only apply filename workaround for string attribute --- Lib/pdb.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 4afd17bf1b0998..78d0ce537f1fc2 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1335,8 +1335,9 @@ def do_list(self, arg): # gh-93696: stdlib frozen modules provide a useful __file__ # this workaround can be removed with the closure of gh-89815 if filename.startswith("