From 7844490e0b338c923b88218e6563c7c903b2ea50 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 25 Nov 2025 13:34:47 +0000 Subject: [PATCH 1/6] fix incorrectly pdb break --- Lib/pdb.py | 4 ++- Lib/test/test_pdb.py | 25 +++++++++++++++++++ ...5-11-25-16-00-29.gh-issue-59000.YtOyJy.rst | 1 + 3 files changed, 29 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 60b713ebaf3d1a..18cee7e9ae60e1 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1487,7 +1487,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 34dfc220c7ed73..99a69ba493a2c3 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4587,6 +4587,31 @@ def bar(): ])) self.assertIn('break in bar', stdout) + def test_issue_59000(self): + script = """ + def foo(): + pass + + class C: + def c_foo(self): + pass + def foo(self): + pass + + foo() + """ + commands = """ + break foo + break C.foo + break C.c_foo + break 10 + continue + break C.foo + quit + """ + stdout, stderr = self.run_pdb_script(script, commands) + self.assertIn("The specified object 'C.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 7b8fe202fbac415c8a851c0226ecc508e1ebecfe Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Sun, 30 Nov 2025 05:07:45 +0000 Subject: [PATCH 2/6] fix test --- Lib/test/test_pdb.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 99a69ba493a2c3..460945c1971dbf 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4590,27 +4590,32 @@ def bar(): def test_issue_59000(self): script = """ def foo(): - pass + test_str = "break foo" class C: - def c_foo(self): - pass def foo(self): - pass + test_str = "break C.foo" foo() + C().foo() """ commands = """ break foo break C.foo - break C.c_foo - break 10 continue break C.foo + continue quit """ stdout, stderr = self.run_pdb_script(script, commands) - self.assertIn("The specified object 'C.c_foo' is not a function", stdout) + res_lines = [x.strip() for x in stdout.splitlines()] + print(res_lines) + # can't set breakpoint before class C is defined, and gives an error + self.assertIn("The specified object 'C.foo' is not a function", res_lines[3]) + # can set correctly after the class C is defined + self.assertRegex(res_lines[6], r"Breakpoint 2 at .*main\.py:7") + self.assertIn('test_str = "break C.foo"', res_lines[8]) + class ChecklineTests(unittest.TestCase): From 25c88198c7a448fccd94422fe183782d9288fc64 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Sun, 30 Nov 2025 11:29:08 +0000 Subject: [PATCH 3/6] fix test --- Lib/test/test_pdb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 460945c1971dbf..ecb21f330ee772 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4609,7 +4609,6 @@ def foo(self): """ stdout, stderr = self.run_pdb_script(script, commands) res_lines = [x.strip() for x in stdout.splitlines()] - print(res_lines) # can't set breakpoint before class C is defined, and gives an error self.assertIn("The specified object 'C.foo' is not a function", res_lines[3]) # can set correctly after the class C is defined From df885343569b6b539fbdfa65a34d77b73c83b3f3 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Mon, 1 Dec 2025 03:24:31 +0000 Subject: [PATCH 4/6] fix test --- Lib/test/test_pdb.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index ecb21f330ee772..281bb0600dc9b3 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4595,26 +4595,13 @@ def foo(): class C: def foo(self): test_str = "break C.foo" - - foo() - C().foo() """ commands = """ - break foo - break C.foo - continue break C.foo - continue quit """ stdout, stderr = self.run_pdb_script(script, commands) - res_lines = [x.strip() for x in stdout.splitlines()] - # can't set breakpoint before class C is defined, and gives an error - self.assertIn("The specified object 'C.foo' is not a function", res_lines[3]) - # can set correctly after the class C is defined - self.assertRegex(res_lines[6], r"Breakpoint 2 at .*main\.py:7") - self.assertIn('test_str = "break C.foo"', res_lines[8]) - + self.assertIn("The specified object 'C.foo' is not a function", stdout) class ChecklineTests(unittest.TestCase): From b59d79aa4a21009d33da23c188e9230f1084e4c9 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Mon, 1 Dec 2025 03:51:27 +0000 Subject: [PATCH 5/6] fix 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 281bb0600dc9b3..848a58b0d01a5f 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4590,7 +4590,7 @@ def bar(): def test_issue_59000(self): script = """ def foo(): - test_str = "break foo" + pass class C: def foo(self): From 53ac2601975bdb6d3c5ff1c89172f9a5a7ab301a Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Mon, 1 Dec 2025 07:23:54 +0000 Subject: [PATCH 6/6] fix 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 848a58b0d01a5f..8d582742499815 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4594,7 +4594,7 @@ def foo(): class C: def foo(self): - test_str = "break C.foo" + pass """ commands = """ break C.foo