From 85716d2a7a0b2d5c30695e9e4b4273d2d4cf8ef3 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 2 Dec 2025 12:41:54 +0800 Subject: [PATCH 1/2] [3.13] gh-59000: Fix pdb breakpoint resolution for class methods when module not imported (GH-141949) (cherry picked from commit 5e58548ebe8f7ac8c6cb0bad775912caa4090515) Co-authored-by: LloydZ <35182391+cocolato@users.noreply.github.com> --- Lib/pdb.py | 4 +- Lib/test/test_pdb.py | 48 +++++++++++++++++++ ...5-11-25-16-00-29.gh-issue-59000.YtOyJy.rst | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-11-25-16-00-29.gh-issue-59000.YtOyJy.rst diff --git a/Lib/pdb.py b/Lib/pdb.py index a990d60fe1c2fd..063b12cc856c21 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1262,7 +1262,9 @@ def lineinfo(self, identifier): f = self.lookupmodule(parts[0]) if f: fname = f - item = parts[1] + item = parts[1] + else: + return failed answer = find_function(item, self.canonic(fname)) return answer or failed diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 92a0180ecc9a06..a4b9ae2ca1789e 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4013,6 +4013,54 @@ def f(x): self.assertIn('42', stdout) self.assertIn('return x + 1', stdout) + def test_zipimport(self): + with os_helper.temp_dir() as temp_dir: + os.mkdir(os.path.join(temp_dir, 'source')) + zipmodule = textwrap.dedent( + """ + def bar(): + pass + """ + ) + script = textwrap.dedent( + f""" + import sys; sys.path.insert(0, {repr(os.path.join(temp_dir, 'zipmodule.zip'))}) + import foo + foo.bar() + """ + ) + + with zipfile.ZipFile(os.path.join(temp_dir, 'zipmodule.zip'), 'w') as zf: + zf.writestr('foo.py', zipmodule) + with open(os.path.join(temp_dir, 'script.py'), 'w') as f: + f.write(script) + + stdout, _ = self._run_pdb([os.path.join(temp_dir, 'script.py')], '\n'.join([ + 'n', + 'n', + 'b foo.bar', + 'c', + 'p f"break in {$_frame.f_code.co_name}"', + 'q' + ])) + self.assertIn('break in bar', stdout) + + def test_issue_59000(self): + script = """ + def foo(): + pass + + class C: + def foo(self): + pass + """ + commands = """ + break C.foo + quit + """ + stdout, stderr = self.run_pdb_script(script, commands) + self.assertIn("The specified object 'C.foo' is not a function", stdout) + class ChecklineTests(unittest.TestCase): def setUp(self): diff --git a/Misc/NEWS.d/next/Library/2025-11-25-16-00-29.gh-issue-59000.YtOyJy.rst b/Misc/NEWS.d/next/Library/2025-11-25-16-00-29.gh-issue-59000.YtOyJy.rst new file mode 100644 index 00000000000000..33ab8a0659e4a2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-25-16-00-29.gh-issue-59000.YtOyJy.rst @@ -0,0 +1 @@ +Fix :mod:`pdb` breakpoint resolution for class methods when the module defining the class is not imported. From 2365035500dbb22672243529291b7e1da19542df Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 1 Dec 2025 20:44:52 -0800 Subject: [PATCH 2/2] Remove test_zipimport method Removed the test_zipimport method from test_pdb.py. --- Lib/test/test_pdb.py | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index a4b9ae2ca1789e..dd31649ab262c3 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4013,38 +4013,6 @@ def f(x): self.assertIn('42', stdout) self.assertIn('return x + 1', stdout) - def test_zipimport(self): - with os_helper.temp_dir() as temp_dir: - os.mkdir(os.path.join(temp_dir, 'source')) - zipmodule = textwrap.dedent( - """ - def bar(): - pass - """ - ) - script = textwrap.dedent( - f""" - import sys; sys.path.insert(0, {repr(os.path.join(temp_dir, 'zipmodule.zip'))}) - import foo - foo.bar() - """ - ) - - with zipfile.ZipFile(os.path.join(temp_dir, 'zipmodule.zip'), 'w') as zf: - zf.writestr('foo.py', zipmodule) - with open(os.path.join(temp_dir, 'script.py'), 'w') as f: - f.write(script) - - stdout, _ = self._run_pdb([os.path.join(temp_dir, 'script.py')], '\n'.join([ - 'n', - 'n', - 'b foo.bar', - 'c', - 'p f"break in {$_frame.f_code.co_name}"', - 'q' - ])) - self.assertIn('break in bar', stdout) - def test_issue_59000(self): script = """ def foo():